Polyglot via Polyglot | skriker.
This post is here to introduce the plugin called “Polyglot” – plugin for complete and easy localization of your blog into several languages. Polyglot is based on Language Picker. If you have any problem reading documentation of Language Picker can be helpful. I have developed it for my private use but some other guys/gals could be interested (hello Mihailo:o) as well.
I have fixed all bugs in Language Picker that I’ve found and added ability to automatically detect the visitor’s preferred language and then choose the right translation for him/her. You can try it here – with this post. Example above should be in czech or english according to your selection or preferred language in your browser.
How it works
For example this post actually looks like this:
[lang_cs]Dva studenti…[/lang_cs]
[lang_en]In a Rhodes tailor shop…[/lang_en]
This post is here to…
And that’s it. You can translate titles of the posts, pages, names of the categories etc. in the same way.
ISO codes
You are supposed to use [lang_xx] where ‘xx’ is the ISO code of the language. These can be found here: ISO codes
Language versions
If you put to your index.php (and single.php, search.php etc.) in your themes something like this:
<?php if(function_exists('polyglot_other_langs')) {
//display existing language versions of the post
polyglot_other_langs(' ','<ul>', '</ul>', '<li>', '</li>');
}?>
(must be inside of the WordPress loop) you allow your visitors to choose the language version of particular post (as could be seen above).
Flags
Name of the language or associated flag will be shown according to the value of $polyglot_settings['use_flags']. (Thx Mateusz Łoskot for inspiration)
Preferred language
Then you can offer your visitors to set preferred language for entire blog (as you see in my menu). It can be done by code like this:
if(function_exists('polyglot_list_langs')){
polyglot_list_langs(false);
}
that you put e.g. in your sidebar.php. Function polyglot_list_langs() accepts one optional parameter true or false that says whether names of languages or flags should be shown.
RSS
You can also offer RSS feeds in different languages:
<a href="<?php bloginfo('url'); ?>?feed=rss2&lang_view=en"> English RSS</a>
Last thing you have to do is to specify languages of your blog in polyglot.php. Basically – you just add ISO codes to the array $polyglot_settings['knownlangs'].
If there is no suitable language version of text present – then the default language version is selected. If even default language version is not there – then only parts that are not translated are shown.
Template localization
Because Polyglot changes dynamically prefered language of your blog – you don’t have to do anything special to translate your blog except that everything in your templates that should be translated must be “gettexed“. And appropriate .mo files must be in your wp-includes/languages directory. You can get them here: WP localization files and they should be renamed to xx.mo where ‘xx’ is the ISO code of certain language.
Time & Date
Time and date formats can be cusomized to fit the language traditions since the versin 0.8.











