WPML Coding API
WPML offers functions that can be used in your WordPress theme to provide correct support for multilingual themes.
| Function | Purpose | Notes | ||
|---|---|---|---|---|
| do_action(‘icl_language_selector’) | Insert the drop down language selector. | Described in the language setup section of the getting started guide. | ||
| do_action(‘icl_navigation_menu’) | Insert the top navigation menu. | Described in the navitaion section of the getting started guide. | ||
| do_action(‘icl_navigation_breadcrumb’) | Insert the breadcrumbs trail. | |||
| do_action(‘icl_navigation_sidebar’) | Insert the sidebar navigation. | |||
| icl_get_home_url() | Link to the home page in the active language. | Described in the home page link section of the getting started guide. | ||
| icl_get_languages(‘skip_missing=N’) | Used for building custom language selectors. | Described in the custom language switcher section of the getting started guide. | ||
| icl_link_to_element(ID, type, text, arguments, anchor) | Used for creating language dependent links in themes. | Described in the hard coded links section of the getting started guide. | ||
| icl_object_id(ID, type, return_original_if_missing, language_code) | Used for calculating the IDs of objects (usually categories) in the current language. | Described in the language dependent IDs section of the getting started guide. | ||
| icl_register_string(context, name, value) | Registers a string for translation | Described in the guide for translating texts in other plugins and themes. | ||
| icl_unregister_string(context, name) | Removes a string from the translation table | |||
| icl_t(context, name, value) | Gets the translated value of a string. | |||
Language constants
WPML defines the following constants which can be used in the theme:
| Constant | Description | Example |
|---|---|---|
| ICL_LANGUAGE_CODE | Code for the current language | fr |
| ICL_LANGUAGE_NAME | Name of current language, in the current language | Français |
| ICL_LANGUAGE_NAME_EN | Name of the current language name in English | French |
Disabling WPML’s CSS and JS files
WPML comes with its own CSS and JS files that style its navigation and drop-down language switcher.
If you don’t need them in your theme, you can tell WPML not to load these files. Do to that, define the following constants in your theme:
| Constant | The file it disables |
|---|---|
| ICL_DONT_LOAD_NAVIGATION_CSS | Navigation stylesheets – cms-navigation-base.css and cms-navigation.css |
| ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS | Drop-down language selector stylesheet – language-selector.css |
| ICL_DONT_LOAD_LANGUAGES_JS | Drop-down language selector Javascript – sitepress.js |
To set these constants, define them in the theme’s functions.php file. For example:
define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
Hi….
Its really a nice plugin given by WPML.org,
I go thoroly….And implement it,
But now one and only problem is I cant found .po and .mo files for each languages I Used.
So please give me Hint, from where can I get those files.
Hi
Thanks for excellent plugin but I’ve got problems using it.
I’ve try to check current language but
gives me only ‘en’ value instead of ‘ru’ when I’m on
http://www.domain.com/ru/whatever.htmlWhat have I do wrong? How to check current language better?
Regards Serguey
This sort of thing is exactly what the forum is used for. Please post it there with details that will allow us to see the problem in your site AND recreate it locally.
Hi … and thanks (from the bottom of my developer heart) for this great plugin!
WMPL is now an integrated part of our WordPress framework. It is the best tool we found to produce stable WP themes for our canadian bilingual clients/users.
About those functions, is there any way to re-use them within TinyMCE WYSIWYG generated contents (
the_content) like somekind of a “shortcode” brackets to generate sticky links ?… Or maybe this technical question is a case for the forum.
Thank’s anyway & Keep on the good work.
Which functions specifically would you use as shortcodes?
does it support ‘hidden’ class for styling currently active language? like .current_page_item in wp itselft to style selected page in navigation.
here is the example what i’m trying to achieve:
http://www.dixevil.com/limoluxx/
Hi there,
Thank you for such a wonderful plugin. I want to be able to auto create empty translation pages for each new post created in my website. which tables, other than the wp_icl_translations are affected?
Only wp_icl_translations. You need to add new rows with other languages and the same trid as the original.
Thank you for the instant response. I will start working on it tonight.
How to find a list of available languages of current site and what language is the main one.
p.s. Thanks for plugin.
Hi, to make our decision, our developer is asking: “Please ask your plugin author (of the plugin that creates multiple domains) how it differentiates between domains. How the plugin determines these domains is important in this scenario.”
Could you please, let us know the variable to get the different domains?
How to get constant (ICL_LANGUAGE_CODE) in my plugin?
echo ICL_LANGUAGE_CODE; not work and print only text “ICL_LANGUAGE_CODE”.
Please help.
Hi i think its because your plugin is loaded after WPML (if you try after all plugins are loaded you’ll find the constants). I’m currently looking a way to lower my plugin loading priority to hook up at last as possible.
hi, in fact you need to wait until WPML has loaded such as on INIT
__construct();
}
function __construct() {
add_action( ‘init’, array( &$this, ‘init’ ) );
}
function init() {
// now you have ICL_LANGUAGE_CODE
}
}
To ease theme development for novice programmers, something like “icl_get_name_of_post( … )”, icl_get_permalink_of_post( … ) etc could be helpful.
amir , how to create a custom wordpress post creator in frontend.
i can add a new post using , wp_insert_post().
But wat value i need to pass for post_content and post_title or something else to create a post in a different language, say arabic..
[...] Links: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query http://wpml.org/documentation/support/wpml-tables/ http://wpml.org/documentation/support/wpml-coding-api/ [...]
WPML is probably the greatest translation related WordPress plugin.
I do try to improve the the easy page link plugin for WPML and I would need some help finding a solution on the linking to pages from another language.
How do I get the language of a post/page if I know its id?
Also, how about incorporating this plugin in WPML, this seams like a basic functionality.
Probably is better to use the tracker at http://github.com/ssbarnea/easy-page-link-for-wpml/issues/issue/1
For anyone looking at getting the language of an element, the function you are looking for is this:
get_language_for_element($element_id, $el_type=’post_post’)
This isn’t working for me, I’m getting an error that function get_language_for_element doesn’t exist.
Is there another way to get the language of an element (or I have to query the db)?
This has changed to:
global $sitepress;
$sitepress->get_language_for_element($element_id, $el_type=’post_post’);
Hi,
I configured your plugin in the admin…but it is showing only one language in dropdown instead of 2 languages(English and Spanish).
Can you help?
You should post about that in our forum:
http://forum.wpml.org
Hello, I want to bulk upload posts from a csv including two languages. I use CSV Importer to create the primary language. Is there a way to create the second language content programmatically?
There is a way, but you’re need to code it. Generally speaking, you should create columns per language. Then, create posts for all languages and connect them using WPML’s language tables. This page explains how WPML assigns language information:
http://wpml.org/documentation/support/wpml-tables/
Hi! Thanks for the great plugin and the tutorial for theme developers. I’m aware that you are dealing with plugin developers separately, to aid them to integrate their plugins better in WPML.
I just wish something dramatically simple. I tend to develop plugins ready to be translated by supplying the appropriate .po/.mo files. On non-WPML-enabled sites, changing the language (either on wp-config.php or through Options > General — which works if you have WordPress with several language files installed) will automatically display the plugin in the appropriate language.
Under WPML, however, Options > General doesn’t display the required dropdown. Instead, WPML has its own way of dealing with the “current” language.
What I wish to know is how to flag my own plugins to recognise that WPML has changed the default language of the admin panel and load the correct language file for the plugin. How is this achieved? I suppose that there is a special hook/action/filter that has to be called, and this cannot be much harder than just adding two or three lines of code at the start of the plugin.
Any pointers would be appreciated; and yes, I’ve browsed the forums, the Internet, and all blogs that talk about WPML
And I’m also trying to reverse-engineer some plugins which I know that work that way to see what “magic” they use to achieve the same effect.
I suppose I could push all translated strings for the plugin’s admin panel into WPML, but that’s overkill: after all, that’s why we have the .po/.mo mechanism to deal with that (meaning that the plugin will be perfectly compatible with non-WPML sites).
Thanks in advance!
What you’re describing is exactly how things work. WPML hooks to the WordPress locale settings and all plugins that call load_plugin_textdomain load the .mo file of the current language.
Hm. I know this is not the right place to enter deep discussions of what works and what doesn’t, but here is just my short feedback. I’ve tried one of my plugins on three different installs with WPML. Two of them are WP 3.1.3, one is WP 3.2 Beta 2. With WPML 2.3.0, what happens is that under WP 3.1.3 my plugin will only load the appropriate .mo file depending on the WPLANG setting on wp-config.php, no matter what is configured under WPML’s default language, admin language, or the new content language dropdown at the top. All these get silently ignored. The behaviour under WP 3.2 Beta 2 seems a bit more erratic, sometimes it seems to work when switching languages under WPML, but it’s not consistent.
It might be a bug on the plugin, though; I’m preparing two further plugins which will support multiple languages as well and see if the behaviour is the same. Or it might be a subtle interplay of the order plugins are loaded: for instance, under my “test” site in WP 3.2 Beta 2, WPML was the last plugin to be installed. The other two sites had WPML installed first and my own plugin last. Well, I guess there is a lot of testing to be done on my part, but thanks for clarifying this issue.
Please discuss this in our forum.
How can I retrieve the translated value of a custom field in the active language?
Hi,
I’d like to show only 1 language in the selector (i.e : if you’re in the french language, only the English link appears to swith toward the english section)
so i need to customize the :
to show only 1 language…
Any idea?
thx!
My code for now :
);
}; ?>
You should use our forum for this. Comments cannot include HTML or PHP.
Hi, I’m using wpml in http://www.deniscimaf.com and it works great with Safari, Firefox and Chrome. But.. with IE I have problem, the IE 8 doesnt show the selector language drop down.
Anyone can help me to find what is going on? I tried to see my css, the lt8.css of my wordpress template, but I dont know where is the problem to fix it.
Thanks!
Hi, this is an amazing plugin to use in my wordpress blog theme. I’m currently adapting it to my bilingual Canadian blog. I’m still having some issue with the IE 8. Do you have any upcoming update that will fix compatibility issue?
This is what i’m trying to achieve. My actual root is http://www.maurisource.com for french and I would like it to have a different index for example http://www.maurisource.com/index_en.php
Any suggestions?
Thanks,
-John.P
We’re not aware of any compatibility issues related with IE8. If you have anything, please report with full details in our forum.
Hello Dear,
I want a help. I put wpml plugin one of my site where i want to use only germany and english language. And i do it and its works. but i want to show it as a “click to change text” basis. i mean where someone click in the english language then dautch text shows and english text gone and again repeat this.
from the wp admin i do the list style select – so its look like list style now – but i want “click to switch”.
i just put now in code
Please use our forum, explain what you’re doing, provide code samples and our support folks will help.
“Described in the navitaion section of the getting started guide.”
Hi
Is there a constant to define the core language ?