Example
Dva studenti hledají brigádu na léto, nejlépe přepisování textů na počítači. Zn. Jsme spolehlivý a pracovitý. (Nalepovaný inzerát na Kladně. Osobně bych radši najal toho pracovitého.)
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.
Permalinks
Permalinks are fully supported, and turned on by default, since version 2.0 was released
Comments
The version 0.8 has also introduced the ability to write comments on posts in more language versions. Your visitors must use [lang_xx] instead of <lang_xx>.
Other useful plugins
You can also try some other of my plugins: IImage Browser, IImage Gallery, IImage Panorama, JÄÅ Preview.
Known issues
- You have to set
WPLANG
(e.g. define('WPLANG', 'en');
) in your wp-config.php
. Thank you Pete!
- If you are using WP older than 1.5 – uncomment part of the code from line 125 and comment part from line 139.
Important
Since version 0.8 you can use [lang_xx] instead of <lang_xx>. That's useful for those using WYSIWYG editors.
Fixes
01.04.2008 – WP 2.5 compatibility improved
27.01.2008 – WP 2.3 compatibility improved (tags, links, initialization,…)
11.10.2007 – few RSS related filters added
27.05.2007 – some setcookie
improvements
22.05.2007 – small improvements related to new features in WP2.2
29.01.2007 – version 2.0 released. Many new features and improvements added (permalinks among others).
24.03.2006 – original WP function trailingslashit
doesn't work as intended so it has been replaced by polyglot_trailingslashit
20.01.2006 extended polyglot_the_date
, now accepts $before
& $after
extended polyglot_list_langs
, now sets a class for the <li>s (language_item
and current_language_item
)
Thanks Jan for all these improvements!
07.01.2006 Tag [lang_xx] added
18.10.2005 Huge update – flags added, 'translate categories' plugin implemented etc.
25.5.2005 Polyglot is now using standard load_default_textdomain()
function.
13.3.2005 Tag <lang_all> is since this moment optional – everything except translated parts is handled as <lang_all>
12.3.2005 Fixed problem with WP1.5 – thanks Matthias.
Download
polyglot2.5.zip.
default_gettext.zip – fully gettexed default theme. (thanks to Maira)
Let me know
I'd appreciate if you let me know that you use Polyglot on your web. You can also choose whether you want to be informed about new versions:
How to translate categories
There are two ways. At first you can write translations directly to the category 'name' using [lang_??]
tags. But WordPress is limiting the name length to just 55 characters so you will have a problem to fit all translations inside. I'd recommend you increasing the length of 'name' column in 'items' table (WP <2.3 – 'cat_name' column in 'categories' table) in your WP database.
Second way is to add all translations of categories to your .mo files and Polyglot will try to translate them. It's tested with wp_list_cats() function.