From a theme with localization to a multilingual theme with xili-language : tests step by step.

When searching in Theme Directory the term « localization« , you only find today three themes, so with the famous kubrik international (default-i8n shipped with wordpress kit), four themes seem to be quite ready for the test of compatiblilty with xili-language.

We have choosen two for this post : Gear and Fusion with for both fine look and design.

Fusion Theme SnapShot

Fusion Theme SnapShot

Gear theme snapshot

Gear theme snapshot

A short introduction :
a multilingual theme is a theme where texts around the post(s) are changed with languages of the parts of the website. There is no automatic translation of the contents of post. The editor has full control how he organize the post, the categories,… He only add another taxonomy : the language of each post. With xili-language plugin, the language of a theme with localization features is adapted (on the fly) to the language of the post or the category.
It is typically a CMS management or a data-design and need good rules.

1) First step :

Verify that all __() and _e() function are correctly in place in theme – In Gear, there is some errors – domain absent – _e(‘Categories’); – or domain inadequate (‘blank’ instead ‘default’)

Search in functions.php file the load_theme_textdomain() line and modify it as below

A) for Gear

243
244
245
246
247
248
249
250
251
function theme_init(){
	if (class_exists('xili_language')) {
		define('THEME_TEXTDOMAIN','default');
		define('THEME_LANGS_FOLDER','/languages');
	} else {
	   load_theme_textdomain('default', get_template_directory() . '/languages');	
	}	
}
add_action ('init', 'theme_init');

B) for Fusion

4
5
6
7
8
9
10
11
12
function init_language(){
	if (class_exists('xili_language')) {
		define('THEME_TEXTDOMAIN','fusion');
		define('THEME_LANGS_FOLDER','/lang');
	} else {
	   load_theme_textdomain('fusion', get_template_directory() . '/lang');	
	}
 
}

In these themes the .mo language files are in subfolder of theme folder, so the two constantes will be used by xili-language plugin if activated.

2) Second step.

Complete the .mo file with the translations of categories (name and description of each), description of the website and other terms by adding lines in .po files and using poEdit. In one other post, we will see how to use xili-dictionary with his UI in the wordpress admin.

If you want to translate the site description, you have to modify on line in header.php :

Exemple in Fusion (header.php) :

142
<div id="topnav" class="description"> <?php _e(get_bloginfo ( 'description' ),'fusion');/*bloginfo('description'); */?></div>

3) Third step :

enrich the layout of the theme by adding some features :
– a list of the available languages (in the sidebar)
– links when similar posts about the same subject translated are present in the website

The list can be added by to way – like a widget or like a template tag.
Note about title of widgets : The titles of default widget shipped with wordpress don’t contain the function _e() or __() with the domain of the theme. So they are not live translatable. We are not fan of widget coding consuming.
Today, it is better to use template tag as here in fusion (sidebar.php) :

50
51
52
53
54
55
56
57
58
59
<!-- sidebar menu (categories) -->
<ul class="nav">
<?php if($options['nojquery']) {
echo preg_replace('@<li([^>]*)><a([^>]*)>(.*?)</a>@i', '<li$1><a$2><span>$3</span></a>', wp_list_categories('show_count=0&echo=0&exlude=181&title_li='));
 } else {
 echo preg_replace('@<li([^>]*)><a([^>]*)>(.*?)</a> (<a ([^>]*) ([^>]*)>(.*?)</a>)@i', '<li $1><a$2><span>$3</span></a><a class="rss tip" $4></a>', wp_list_categories('show_count=0&echo=0&exlude=181&title_li=&feed=XML')); } ?>
<?php if (function_exists('xili_language_list')) {
xili_language_list();
} ?>
</ul>

Links under each post title in single display (single.php)
Only add the template tag just under the_title().
Here in Gear (item.php)

12
13
14
15
16
17
18
<span class="comment">
<a href="<?php comments_link(); ?>"><?php comments_number( __( 'No comments', 'default' ), __( '1 comment', 'default' ), __( '% comments', 'default' ),  __( 'comments', 'default' )); ?></a>
 
</span>
<br/ >
<small><?php xiliml_the_other_posts($post->ID) ?></small>
<?php } ?>

Pause : now the site is multilingual with the default functions delivered with xili-language plugin.

When you modify a post or a page – of necessary – set his language :

Setting the language of post before publish

Setting the language of post before publish

See result in Gear and in Fusion

In Fusion :

Here it is after a search of french term « bienvenue » :

Fusion SnapShot (french search)

Fusion SnapShot (french search)

In Gear :

gear theme with a french post

gear theme with a french post

Future step

These two themes are now « multilingual » and :
If you need to modify the default rules when template language changes or enrich the style of some template_tags (as in snapshots with flag or more else), it is possible with the hooks of the plugin himself and some functions added in functions.php file.

It is the subject of another following post (next episode soon…).

MS 090306

Ce contenu a été publié dans Plugins WP, Studies, xili-language, avec comme mot(s)-clé(s) , , . Vous pouvez le mettre en favoris avec ce permalien.

11 réponses à From a theme with localization to a multilingual theme with xili-language : tests step by step.

  1. admin dit :

    Question : Do you plan to write a french version of this post ?
    Answer (réponse) : Yes, Oui dans les prochains jours… patience

  2. Ping : Wordpress-Sites in mehreren Sprachen

  3. Ping : Wordpress-Sites in mehreren Sprachen / Design, Webdesign / Seraph Design Solutions // Webdesign, Printdesign, Leveldesign // Portfolio von Benjamin Schulz

  4. Jignesh dit :

    hello,
    I have installed wordpress 2.7 can you please guide me how to install plugin this version of wordpress because in function.php i am not able to find load_theme_textdomain() function.

    Thanks,
    Jignesh

  5. admin dit :

    You must choose first a wordpress theme « international » with localization like default-i18n or fusion or gear or….

  6. Hong dit :

    how to use this?
    wordpress2.8,give me a DOM;
    please tell me!
    thanks!

  7. salik dit :

    hi i follow the step but its not working on my end

  8. xiligroup dev dit :

    Please open a discussion in forum http://forum.dev.xiligroup.com/ and inside be more precise. Is is possible to have your website URL ?

    dev.xiligroup.com team

  9. Developer dit :

    It works. Thanks for posting.

  10. Ping : » Blog Archive » 如何做多語言版本網頁

  11. Ping : WordPress in mehreren Sprachen « AFD PC-SERVICE Armin Fischer, Regensburg . www.afd-pc-service.de .

Laisser un commentaire