Saturday, September 17, 2011

Wordpress WPML Edits

In one of my recent projects I had to use WPML, a very well done plugin for Wordpress for Multi Languages sites. It is based on the idea of keeping translations of different posts in another posts linked to the first one. This way the problem of translated URLs is solved in a very elegant manner. Also all fields appear only one time per translation (which is really nice. If you have 10 fields and you need to translate it in almost 30 languages you won't end up with almost 300 fields on a post edit page).

My problem appeared when I had to define some custom languages and then I wanted to change their names. On a site there can be different content for users whith IP from Europe and have their browser set to English and users with IP from US and their browser language set to I need the default en plus some user defined language, let's say en-euro. If instead of en-euro I wanted to use en-emea the only possible solution would have been to define the new language and use the new one. So, I ended up looking in all _icl tables and try to figure out where the language codes are used. Same thing for a language name. After updating information in those tables the changes were not visible unless I deleted the plugin's cache (kept in wp_options, option_name='_icl_cache').

There are some risks in using my new plugin:
  • I didn't test it for all types of WPML translations;
  • I don't know what happens if one had already made mane translations and then deletes the plugin's cache from wordpress' database (of course, I can figure out from WPML code, but I had been too busy for that. If I get any emails with problems related to this issue described I will try to go deeper into this issue);
  • There might be still hidden issues with this approach (maybe the creators of the WPML plugin had their reasons not to include this option. On edit languages form the fields for language name and code are disabled...)
I recommend using my plugin before starting to translate, if possible. The plugin can be downloaded from here.

After you copy the .zip's content into wp-content/plugins directory and you activate it, a new option will appear under Settings menu called WPML Edits. When you click on it a form will appear where you can set the Old code, New code, Old name and/or New name and when you click Apply changes the database updates run. You need to use an already existing code/language name for Old code and Old name values and a not already existing code/language name for New fields values.

No comments: