WPML / The WordPress Multilingual Plugin

Installation

WPML uses the Installer plugin for automated, safe and easy installation. There’s a one-time setup process, described below. After this setup process, WPML downloads and upgrades will automatically appear in your site’s Plugins section.

1. Go to Installer plugin page and download from there.

2. Unzip Installer and upload to your site’s ‘wp-contents/plugins’ directory.

3. Log in to your site, go to Plugins and enable Installer.

4. Click on Plugins->Add new and search for WPML Multilingual CMS.

5. Click the WPML.org tab, find the plugin and click on the ‘login’ link right next to it.

A window will open, asking for your login details.

Log in to WPML.org

Log in to your WPML.org account, with your username and password. We’ll save your details encrypted and use them whenever there’s an upgrade to WPML, to get new versions automatically.

6. Once logged in, you’ll see that the ‘login’ and ‘buy’ links are gone. Instead, the familiar Install Now links will appear, on WPML’s components.

Note: if you purchased Multilingual Blog, only base WPML plugin will be available to download (WPML Multilingual CMS). You’ll see ‘upgrade’ links next to the other components.

Click on the Install Now links to download and install WPML.

Plugin could not be activated because it triggered a fatal error

If the installation triggers the message above, then open your php.ini and change this line:

max_execution_time = 3000

Configuring WPML

After you enable WPML, you’ll see a Multilingual Widget in the Admin Dashboard. This widget provides access to the different functions in WPML. You can also access them through the WPML menu.

Site Languages

When you configure WPML for the first time, you need to choose the language of existing content. Then, add more languages to the site. You can always go back to add / remove languages. Make sure you choose the correct default language, in order to avoid bugs later in your attempt to change it.

Hiding languages until ready

You can completely hide content in specific languages from visitors and search engines, but still view it yourself. This allows reviewing translations that are in progress.

Just make sure that you go to your profile page and on the hidden languages section, tick Display hidden languages.

Changing the Language Names

In order to change the language name go to “WPML > Site languages”, press on link “Edit languages”, adjust the names and press “Save”.

String Translation

Anything that doesn’t fall inside posts, pages or taxonomy goes into String Translation. This includes the site’s tagline, general texts in Admin screens, widget titles and many other texts.

How to translate hard-coded strings in PHP

01. Change “WPML > Theme and plugins localization > Select how to localize the theme” to “Translate by WPML”.

02. In you PHP page file template, add something like this:

<?php _e('The string I want to translate', 'My-theme'); ?>

03. Go back to WPML > Theme and plugins localization and press “Scan the theme for strings”.

04. In “WPML > String Translation”, your new strings will appear in the list and now you can translate them in the available languages.

WPML and batch translations

For batch translation purposes download and activate the WPML Translation Management plugin. The process is this:

  1. Go to translation management menu page.
  2. Tick the traslations you want to do.
  3. Tick the languages (or translate all) and press Send Documents.
  4. Now if you go to the translations menu page you will see the translation jobs.
  5. Press the edit right next to the translation you want to do.
  6. Enter the title, the body content and press save.

WPML and images

When you translate content that includes attachments, such as images, audio or video files, you might want to use the exact same media files in different languages. The Media Translation module lets you easily reuse the same files in content in different languages.

WPML and types

In order to use WPML with the Types plugin, make sure you have installed the WPML Translation Management plugin.

You can go to WPML / Translation Management and in the Custom Field Translation find the relevant custom fields and set the default settings. For example, you may have a custom field that is the same in all languages. Just check the radio button for this field to Copy from original to translation.

Widgets

WPML lets you translate widget titles and the body of text widgets. Sometimes, it’s not enough and you want to have completely different widgets for each language. You can use the Widget Login plugin to do so. Here are the steps:

  1. Install and activate Widget Login plugin.
  2. Add multiple copies of the widget to the Widget Area. Each of these widgets will be active in only one language, so we need as many copies as the number of languages we have.
  3. Add language conditions per widgets. Click to edit each of these widgets and add the language conditions to the Widget Logic field. For example, for English we add:
ICL_LANGUAGE_CODE == 'en'

This condition tells Widget Code to display this widget only on English pages.

We repeat this for all the copies that we created.

If conditional for languages

Add this in your functions.php:

<?php
function is_lang($lang) {
    return (ICL_LANGUAGE_CODE == $lang) ? true : false;
}
?>

To get the WPML language selector using PHP:

<?php do_action('icl_language_selector'); ?>

Home page link

When you’re using WPML, the home page address is modified per language. The correct syntax for pointing eg. a logo to your translated home page is:

<a href="<?php echo icl_get_home_url(); ?>">

Get permalink on current language

Add this function in functions.php:

function get_permalink_current_language($post_id) {
    $language = ICL_LANGUAGE_CODE;
    $lang_post_id = icl_object_id($post_id, 'page', true, $language);
    $url = "";
    if ($lang_post_id != 0) {
        $url = get_permalink($lang_post_id);
    } else {
        // No page found, it's most likely the homepage
        global $sitepress;
        $url = $sitepress->language_url($language);
    }
    return $url;
}

Language dependent IDs

icl_object_id(ID, type, return_original_if_missing,language_code)

  • ID – the ID of the post, page, tag or category
  • type – ‘post’, ‘page’, ‘post_tag’, ‘category’ or ‘product’
  • return_original_if_missing – true if WPML should return the ID of the original language element if the translation is missing or false if WPML should return a NULL if translation is missing.
  • language_code (optional) – if set, forces the language of the returned object and can be different than the displayed language.

The ID argument can be the ID of the object in any language. What the function will do is look up the translation group for that object and then the ID of the corresponding object in the active language.

Example usage

$greek_page_id = icl_object_id(get_the_ID(), 'page', false, 'el'); // get the greek translated page id
$greek_page_id = icl_object_id(get_the_ID(), 'category', false, 'el'); // get the greek translated category id (works with products too)

How to get the translated taxonomy object

If you have the option to ‘automatically adjust ids’ on (Under Languages), then use the code below:

global $sitepress;
remove_filter('get_term', array($sitepress,'get_term_adjust_id'), 1, 1);
$original_term = get_term( $original_term_id, 'my-taxonomy' );
add_filter('get_term', array($sitepress,'get_term_adjust_id'), 1, 1);

How to remove the professional translation box

Add this in your functions:

define("ICL_DONT_PROMOTE", true);

How to check if WPML is activated

if ( function_exists('icl_object_id') ) {
    // do something here
}

Adding a class per language to the opening body tag

Add this in your functions:

add_filter('body_class', 'append_language_class');
function append_language_class($classes){
    $classes[] = ICL_LANGUAGE_CODE;  //or however you want to name your class based on the language code
    return $classes;
}

The translation symbols are greyed out

This may happen for a user that is not administrator, eg. an editor. To overcome this:

  1. Go to WPML > Translation management > Translators
  2. Press edit languages right next to the user
  3. Add all existing pairs

WPML is slowing down the backend

WPML has two features which are great for translating, but make everything work slow – just for you (not for visitors). You can disable them.

Go to WPML->String Translation.

The first thing is:

“Track where string appear on the site”

With this, WPML keeps record of the PHP and HTML that called strings in the site. With this, if you see a string and you’re not sure where it’s used, WPML will tell you (click on the little ‘document’ icon next to the string). To work, this feature writes to the DB when strings are shown. Obviously, it slows things down.

The other thing is:

“Auto register strings for translation”

WPML will check if translatable strings are already registered in the String Translation table and, if not, add them. This is pretty useful if your site uses dynamically generated strings that WPML cannot locate when scanning the PHP code.

These two options are great to help you translate, but require many database accesses. They affect you as logged in Admin, but not affect visitors. You can switch them off if you have no use for them.

If the problem still persists, try to update to PHP 5.3 or higher. Why? wpml-string-translation\inc\functions.php -> line 2297 uses debug_backtrace(). Newer PHP versions have an extra parameter to limit the “nesting level”.

Problem loading page

If you site does not load and you have an error “The page isn’t redirecting properly”, than try this:

  1. Go to WPML > Support.
  2. Click the troubleshooting link.
  3. Click the Fix element_type collation button.

Post A Comment

Anti-Spam Quiz: