Why xili-language plug-in ?
When creating a multilingual theme, it is possible to add in functions.php – this line :
load_theme_textdomain('mythemename'); |
and in template file, each text like this : ‘this text’ is replaced in php by _e(‘this text’,’mythemename’) or __(‘this text’,’mythemename’)
example of this site sidebar:
<div class="inside"> <h2><?php _e('Navigation','xilidev') ?></h2> <ul class="counts"> <?php wp_list_categories('sort_column=name&show_count=1&hierarchical=1&title_li=&style=list'); ?> </ul> <br /> <h2><?php _e('Languages','xilidev') ?></h2> <ul class="langs"> <?php if (function_exists('xili_language_list')) { xili_language_list(); } ?> </ul> <br /> <h2><?php _e('Recent posts','xilidev') ?></h2> <ul class="recents"> |
and if the theme folder contain a .mo file (i.e fr_BE) corresponding to the default language set (i.e. define (‘WPLANG’, ‘fr_BE’);) in wp-config.php, the theme’s terms are now translated.
In « default-i18n » multilingual theme ‘mythemename’ is replaced by ‘kubrick’ in – load_theme_textdomain(‘kubrick’) ; – placed at beginning of the functions.php file inside the theme folder.
Extract of first lines of functions.php :
2 3 4 5 6 7 8 9 10 11 12 | if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>', )); load_theme_textdomain('kubrick'); function kubrick_head() { |
But it is impossible to change the terms on the fly ! Only the language of the theme is the language of the blog set in config.php. If you want to have some posts (some parts in the blog) in different languages, the context of the theme does not change (menu, list, category’s names or descriptions )…
Note : a multilingual blog (or cms site) does’nt contain always posts having the equivalent in another language. xili-language allow to the author to choose the language of the current post and to link to another equivalent posts in other languages. This way is more flexible. The translations or adaptations are human-made.
Coding
As short as possible : by reusing WP functions, this plug-in is very light and so easy to maintain or update.
The plugin use current WP tables, options and taxonomy tools.
If the plug-in is not activated, the theme must work : it is why the plug-in use the .mo files present in the theme folder. A theme creator must not forget to write term inside function _e(‘My exemple of title’,’mythemename’) and directly inside html tags.
The webmaster can change the rules of context translations.
By default, inside the plugin file, there are some functions to ‘hook’ the way how some current tags of a theme depending the language of a post or of a category displayed in the theme. If the webmaster or the theme authors add some functions in his functions.php, it is possible to adapt the rules to the design and the CMS.
Why xili-dictionary plug-in ?
The WP source use .mo files to read translation terms dictionnary. But you need to use tools like PoEdit to build working files and upload it to the server if the translated files are not ready made by the theme’s author.
Here, with this plug-in via the admin UI, it is possible to import a .po file, to update it and to create on the fly the .mo file of the target language in the current theme folder. It is a simple tool, but it can be helpful when PoEdit is not available on your current computer.
This plug-in is not mandatory if you prefer to use PoEdit or equivalent tools. The dictionnary is installed in the terms table with a taxonomy « dictionary ». It is full compatible with xililanguage and the preset languages of your site.
The blog and theme’s authors and creators corner :
What things to prepare before to activate the xili-language plugin ?
Check if all the terms of your theme are translatable (with _e() or __() functions). If a term is not translatable (ie blogname or trademark, don’t use these functions.
Create a .pot file containing all the themes terms and add in it all the terms of the categories (name and description).
Generate the .po files for each language and create .mo (ie. en_US.mo, de_DE.mo, fr_BE.mo,…)
Your theme is now international even if the plug-in is not activated.
Before activating the plugin, the only thing to do is to comment the line with load_theme_textdomain() and replace it by a define to set a constant used by the xili-language plugin like here at the top of your functions.php file of the international theme (below example):
/*load_theme_textdomain('xilidev');*/ define('THEME_TEXTDOMAIN','xilidev'); |
Xili-language offers two new tags for theme.
xiliml_the_category()
and
xiliml_the_other_posts()
xiliml_the_category() inserted in the loop (before or after each post) shows a list of the categories where the post is filled.
Here exemple used at end of each post :
the_tags('Tags: ', ', ', '<br />'); the_author() ?> | <?php the_date(); echo " | "; the_time() ?> <?php if (!is_page()) xiliml_the_category(', '); ?> | <?php edit_post_link(__('Edit This')); |
xiliml_the_other_posts() inserted just after the title shows the list of languages in which this post is translated or adapted. The links go to these posts.
<h1><?php the_title(); ?></h1> <small><?php the_time(__('F jS, Y','xilidev')) ?> - </small><small><?php xiliml_the_other_posts($post->ID) ?></small> |
This site and xiliphone site is powered with this plugin.
Here the download link xili-language plugin in wordpress plugin repository…
MS 090123 – updated 090305
Ping : xiliphone kit » multilingual : xili-language plugin
Ping : xiliphone kit » nouveau moteur multilingue
Is it possible to link posts from one language to another with another language ?
Yes – easily – by using Custom Fields in writing post admin part. The only thing to have before is the ID of the other post and his language. Example : the target post is in french : the custom field is ‘lang-fr_fr’ and the value of this field is the ID of the target post.
How to show the link ?
By adding the tag – < ?php xiliml_the_other_posts($post->ID) ?> inside your theme (below the title !).
Q : In the search form in footer of the site, there is a series of radiobutton with languages to limit the search. How to implement them ?
A : The next future release of xili-language plugin (0.9.5) will include a new template tags to add to search form just after input.
Ping : xili-language review, discussions, does it work, and ratings on Loadwp.com | Loadwp.com