Toolbox: xili-language plugin for a multilingual website in one table
|
Name
|
Definition
|
Comment
|
Example
|
Concern
|
WIDGETS
|
to enrich widget enable themes
|
|
Theme
|
Languages list
|
Display the list of available languages
|
Multiple widgets possible. If your theme contains functions that offer widget personalization, the item type must be filled. (see this post)
|
|
sidebar
|
Recent comments
|
Display the list of recent comments in current displayed language.
|
This widget was created because the default one cannot be translatable or offer sub-selection in one language.
multiple widgets possible
|
|
sidebar
|
Recent posts
|
Display list of recent posts in a choosen language
|
since v 1.4.0 for WP >2.8
This new widget solves conflicts or issues occuring when WP default widget is present (contains an obscur `wp_reset_query`). Also a choice of language of this list of recent posts is possible – not necessary the same of the current page. And you can install multiple widgets. Replace WP Recent Widget by this one named – List of recent posts –
multiple widgets possible with different languages (fixed or dynamic)
|
----
|
sidebar
|
|
|
|
|
|
TEMPLATE TAGS
|
usable by theme’s designer and webmaster
|
|
Theme
|
xiliml_the_other_posts default parameters:
($post_ID,$before = « This post in », $separator = « , « , $type = « display »)
|
in loop display the link of other posts defined as in other languages
|
can be used in theme template in single.php under the title
* example: if(class_exists(‘xili_language’)) xiliml_the_other_posts($post->ID)
(in the example, the default template tag was hooked to display flag – see hooks rows below)
|
|
post – page – loop
|
xili_post_language default parameters: ($before = ‘<span class= »xili-lang »>(‘, $after =’)</span>’)
|
in loop display the language of the post
|
Useful inside a multilingual category loop.
|
<div class="postsubtitleinfo">
<small><?php
the_time(); /*__('F jS, Y','xilidev')*/
echo " - ";
if (class_exists('xili_language')) xili_post_language(); ?></small></div> |
<div class="postsubtitleinfo">
<small><?php
the_time(); /*__('F jS, Y','xilidev')*/
echo " - ";
if (class_exists('xili_language')) xili_post_language(); ?></small></div>
|
loop, category, search
|
xili_language_list default parameters: ($before = ‘<li>’, $after ='</li>’, $theoption= »)
|
outside loop (sidebar) display the languages of the site (used also by widget)
|
When the theme don’t enable widget. Use this template tag to display the list in sidebar or (header and footer)
|
<h2><?php _e('Languages','xilidev') ?></h2>
<ul class="langs">
<?php if (function_exists('xili_language_list')) {
xili_language_list('<li>','</li>','siderss');
} ?>
</ul> |
<h2><?php _e('Languages','xilidev') ?></h2>
<ul class="langs">
<?php if (function_exists('xili_language_list')) {
xili_language_list('<li>','</li>','siderss');
} ?>
</ul>
|
sidebar
|
xiliml_the_category default parameters: ($post_ID, $separator = ‘, ‘ ,$echo = true)
|
replace the_category() tag of WP Core
|
The current template tag the_category is not hookable by plugin. So here the categories list of a post inside loop will be translated according the language of the current post.
|
<p class="postmetadata"><?php the_tags(__('Tags: ','xiliips'), ', ', '<br />'); echo " "; _e('Posted in','xiliips'); echo " ";
if (class_exists('xili_language')) {
xiliml_the_category(get_the_ID(),', ');
} else {
the_category(', ');
} ?> | <?php edit_post_link(__('Edit','xiliips'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »','xiliips'), __('1 Comment »','xiliips'), __('% Comments »','xiliips')); ?></p> |
<p class="postmetadata"><?php the_tags(__('Tags: ','xiliips'), ', ', '<br />'); echo " "; _e('Posted in','xiliips'); echo " ";
if (class_exists('xili_language')) {
xiliml_the_category(get_the_ID(),', ');
} else {
the_category(', ');
} ?> | <?php edit_post_link(__('Edit','xiliips'), '', ' | '); ?> <?php comments_popup_link(__('No Comments »','xiliips'), __('1 Comment »','xiliips'), __('% Comments »','xiliips')); ?></p>
|
post – page – loop
|
xiliml_langinsearchform default parameters: ($before= »,$after= »)
|
Template Tag insertable in search form for sub-selection of a language
|
As in example, this function add a way to limit the search to a target language.
|
<h2><?php _e('Search','xilidev') ?></h2>
<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="s" id="s" size="15" value="<?php the_search_query(); ?>" />
<input type="submit" value="<?php _e('go','xilidev'); ?>" /><br/>
<?php if(function_exists('xiliml_langinsearchform')) xiliml_langinsearchform ('<span class="radiosearch" >','</span>') ?>
</form> |
<h2><?php _e('Search','xilidev') ?></h2>
<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="s" id="s" size="15" value="<?php the_search_query(); ?>" />
<input type="submit" value="<?php _e('go','xilidev'); ?>" /><br/>
<?php if(function_exists('xiliml_langinsearchform')) xiliml_langinsearchform ('<span class="radiosearch" >','</span>') ?>
</form>
|
search – sidebar
|
|
|
|
|
|
FUNCTIONS
|
usable by developer with knowledges in php (see php source)
|
|
CMS
|
the_curlang()
|
|
|
|
theme
|
the_cur_langs_group_id()
|
|
|
|
|
the_xili_local_time default parameters: ($format=’%B %d, %Y’,$time = null)
|
|
|
|
time
|
get_cur_language ($post_ID)
|
Return the language of current post in loop
|
|
see below
|
loop
|
get_cur_post_lang_dir ($post_ID)
|
Return the lang and dir of language of current post in loop.
|
The example on right uses this tag and the above one.
|
while (have_posts()) : the_post();
$langdir = ((function_exists('get_cur_post_lang_dir')) ? get_cur_post_lang_dir($post->ID) : array()); ?>
<div class="story <?php echo $langdir['direction'] ?> <?php echo 'borders_'.get_cur_language($post->ID); /*style*/ ?>"> |
while (have_posts()) : the_post();
$langdir = ((function_exists('get_cur_post_lang_dir')) ? get_cur_post_lang_dir($post->ID) : array()); ?>
<div class="story <?php echo $langdir['direction'] ?> <?php echo 'borders_'.get_cur_language($post->ID); /*style*/ ?>">
|
loop
|
xiliml_get_lang_object_of_post ($post_ID)
|
Return language object of a post.
|
|
|
loop
|
choice_of_browsing_language()
|
Return the language of current browser.
|
|
|
visitor’s browser
|
choice_of_browsing_lang_dir()
|
Return the lang and dir of current browser.
|
|
|
visitor’s browser lang and direction
|
add_again_filter ($filtername,$filterfunction)
|
Activate hooks of plugin in class.
|
Reserved for high level developers – see code of function below
|
|
|
xiliml_get_category_link ($catid = 0)
|
Replace get_category_link to bypass hook from xili_language
|
|
|
|
xiliml_recent_comments
|
Recent comments – used by xili widget – usable if you need to create your own template tag
|
|
|
comments
|
xiliml_get_language ($lang_nameorslug= » »)
|
Return full object of a language
|
|
|
|
ex_pages_by_lang ($pages, $r)
|
sub selection of pages for wp_list_pages()
|
example to use as hook
|
|
sidebar
|
function xiliml_force_loop_lang ($lang_query_tag)
|
functions to change loop’s query tag of language
|
useful for sidebar widgets and latest posts widget – since 1.3.0
Even if the main loop is in one language, in the sidebar, it is possible to « force » the language in another one for the widgets.
|
<?php
xiliml_force_loop_lang("fr_fr");
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar top')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?>
<?php
xiliml_force_loop_lang("en_us");
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar topus')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?> |
<?php
xiliml_force_loop_lang("fr_fr");
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar top')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?>
<?php
xiliml_force_loop_lang("en_us");
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar topus')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?>
Another example :
<?php
//echo the_curlang();
/* in this case, the widgets are forced as current lang of the theme - useful in home when query tag 'lang' is not defined -*/
xiliml_force_loop_lang(the_curlang());
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar top')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?> |
<?php
//echo the_curlang();
/* in this case, the widgets are forced as current lang of the theme - useful in home when query tag 'lang' is not defined -*/
xiliml_force_loop_lang(the_curlang());
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar top')) : ?>
<ul>
<li>?</li>
</ul>
<?php endif; xiliml_restore_loop_lang(); ?>
|
sidebar, widget
|
xiliml_restore_loop_lang ()
|
functions to restore loop’s query tag of language
|
see above
|
Snapshot of example above
|
sidebar, widget
|
xiliml_add_lang_to_parsed_query ()
|
function for filter ‘parse_query’ to authorize lang query tag in custom WP_Query()
|
since 1.4.0
useful for function or plugin that put posts inside post…
|
/* example: */
add_action('parse_query','xiliml_add_lang_to_parsed_query');
$r = new WP_Query($thequery);
remove_filter('parse_query','xiliml_add_lang_to_parsed_query'); |
/* example: */
add_action('parse_query','xiliml_add_lang_to_parsed_query');
$r = new WP_Query($thequery);
remove_filter('parse_query','xiliml_add_lang_to_parsed_query');
|
loop, custom queries
|
|
|
|
|
|
SHORTCODE
|
|
|
|
|
linked post
|
example of shortcode using plugin functions
|
this code can be inserted in dedicaced functions detectable inside this folder: wp-content/plugins/xilidev-libraries – see this post –
|
(<em>[linkpost lang="fr_FR"]Cette page en français[/linkpost]</em>) |
(<em>[linkpost lang="fr_FR"]Cette page en français[/linkpost]</em>)
|
post content
|
|
|
|
|
|
|
|
|
|
|
HOOKS
|
Main functions and template tags of xili-language are modifiable by hooks to have better and adapted CMS behaviour.
It is useful for developer with deep knowledges in php and wp (see end of php source)
|
|
CMS
|
xiliml_the_category
add_action (‘xiliml_the_category’,’your_xiliml_the_category’,10,3)
|
|
template tag
|
xiliml_the_other_posts
add_action(‘xiliml_the_other_posts’,’your_xiliml_the_other_posts’,10,3)
|
|
template tag
|
xili_post_language
add_action(‘xili_post_language’,’your_xili_post_language’,10,2)
|
|
template tag
|
xili_language_list
add_action(‘xili_language_list’,’your_xili_language_list’,10,3)
|
In this example described formerly, the list of languages is enriched by flags:
function my_xili_language_list($before = '<li>', $after ='</li>',$theoption) {
global $wp_query;
if ($theoption == 'top') { /* usable in type item in new multiple widget */
$listlanguages = get_terms_of_groups_lite (the_cur_langs_group_id(),TAXOLANGSGROUP,TAXONAME,'ASC');
$a ='';
$currenturl = get_bloginfo('siteurl').'/?';
foreach ($listlanguages as $language) { //QUETAG
if ($language->slug != 'ar_ar' && $language->slug != 'ar_ma') {
$a .= $before ."<a href='".$currenturl."hlang"."=".$language->slug."' title='".__('Latest posts selected',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>"." <img src='".get_bloginfo('template_directory')."/images/flags/".$language->slug.".png' alt='' /></a>".$after;
}
}
echo $a;
} else { /* the current list in sidebar with category sub selection*/
if (is_category()) {
$catcur = xiliml_get_category_link();
$currenturl = $catcur.'&';
} else {
$currenturl = get_bloginfo('siteurl').'/?';
}
$listlanguages = get_terms_of_groups_lite (the_cur_langs_group_id(),TAXOLANGSGROUP,TAXONAME,'ASC');
foreach ($listlanguages as $language) {
if ($language->slug != 'ar_ar' && $language->slug != 'ar_ma') {
if ($before=='<li>') {
if (the_curlang() == $language->slug) {
$beforee = '<li class="current-cat" >';
} else {
$beforee ='<li>';
}
}
$a .= $beforee ."<a href='".$currenturl.QUETAG."=".$language->slug."' title='".__('Posts selected',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>"." <img src='".get_bloginfo('template_directory')."/images/flags/".$language->slug.".png' alt='' /> ". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after;
}
}
if (is_category()) {
$currenturl = xiliml_get_category_link();
$a .= $before."<a href='".$currenturl."' title='".__('Posts of current category in all languages',THEME_TEXTDOMAIN)."' >"." <img src='".get_bloginfo('template_directory')."/images/flags/www.png' alt='' /> ".__('in all languages',THEME_TEXTDOMAIN)."</a>".$after;
}
echo $a;
}
}
add_action('xili_language_list','my_xili_language_list',10,3); |
function my_xili_language_list($before = '<li>', $after ='</li>',$theoption) {
global $wp_query;
if ($theoption == 'top') { /* usable in type item in new multiple widget */
$listlanguages = get_terms_of_groups_lite (the_cur_langs_group_id(),TAXOLANGSGROUP,TAXONAME,'ASC');
$a ='';
$currenturl = get_bloginfo('siteurl').'/?';
foreach ($listlanguages as $language) { //QUETAG
if ($language->slug != 'ar_ar' && $language->slug != 'ar_ma') {
$a .= $before ."<a href='".$currenturl."hlang"."=".$language->slug."' title='".__('Latest posts selected',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>"." <img src='".get_bloginfo('template_directory')."/images/flags/".$language->slug.".png' alt='' /></a>".$after;
}
}
echo $a;
} else { /* the current list in sidebar with category sub selection*/
if (is_category()) {
$catcur = xiliml_get_category_link();
$currenturl = $catcur.'&';
} else {
$currenturl = get_bloginfo('siteurl').'/?';
}
$listlanguages = get_terms_of_groups_lite (the_cur_langs_group_id(),TAXOLANGSGROUP,TAXONAME,'ASC');
foreach ($listlanguages as $language) {
if ($language->slug != 'ar_ar' && $language->slug != 'ar_ma') {
if ($before=='<li>') {
if (the_curlang() == $language->slug) {
$beforee = '<li class="current-cat" >';
} else {
$beforee ='<li>';
}
}
$a .= $beforee ."<a href='".$currenturl.QUETAG."=".$language->slug."' title='".__('Posts selected',THEME_TEXTDOMAIN)." ".__('in '.$language->description,THEME_TEXTDOMAIN)."'>"." <img src='".get_bloginfo('template_directory')."/images/flags/".$language->slug.".png' alt='' /> ". __('in '.$language->description,THEME_TEXTDOMAIN) ."</a>".$after;
}
}
if (is_category()) {
$currenturl = xiliml_get_category_link();
$a .= $before."<a href='".$currenturl."' title='".__('Posts of current category in all languages',THEME_TEXTDOMAIN)."' >"." <img src='".get_bloginfo('template_directory')."/images/flags/www.png' alt='' /> ".__('in all languages',THEME_TEXTDOMAIN)."</a>".$after;
}
echo $a;
}
}
add_action('xili_language_list','my_xili_language_list',10,3);
|
template tag
|
xiliml_langinsearchform
add_action(‘xiliml_langinsearchform’,’your_xiliml_langinsearchform’,10,2)
|
|
sidebar
|
xiliml_cat_language
add_filter(‘xiliml_cat_language’,’my_rules_for_cat_language’,2,3);
|
Exemple to show translated and original item
function my_rules_for_cat_language ($content, $category = null, $curlang='') {
if (!is_admin()) : /*to detect admin UI*/
$new_cat_name = __($category->name,THEME_TEXTDOMAIN);
if ($new_cat_name != $content) :
$new_cat_name .= " (". $content .") ";
endif
else :
$new_cat_name = $content;
endif;
return $new_cat_name;
}
add_filter('xiliml_cat_language','my_rules_for_cat_language',2,3); |
function my_rules_for_cat_language ($content, $category = null, $curlang='') {
if (!is_admin()) : /*to detect admin UI*/
$new_cat_name = __($category->name,THEME_TEXTDOMAIN);
if ($new_cat_name != $content) :
$new_cat_name .= " (". $content .") ";
endif
else :
$new_cat_name = $content;
endif;
return $new_cat_name;
}
add_filter('xiliml_cat_language','my_rules_for_cat_language',2,3);
|
sidebar
wp list categories
content
|
head_insert_language_metas
add_filter(‘head_insert_language_metas’,’my_head_insert_language_metas’,1,2);
|
|
header xhtml
|
head_language_attributes
add_filter(‘head_language_attributes’,’my_ head_language_attributes’,1,1);
|
|
header xhtml
|
xiliml_cur_lang_head
add_filter(‘xiliml_cur_lang_head’,’my_xiliml_cur_lang_head’,1);
|
default rules – set curlang in head according rules
|
multilingual behaviour (front, cat, search,…)
|
More technical hooks and filters inside xili-language
(Read the plugin php source for more infos)
|
|
|
choice_of_browsing_language
|
|
|
xiliml_link_translate_desc
|
|
|
xiliml_single_cat_title_translate
|
used by filter for wp_title() tags – since 1.4.1
|
|
xiliml_getarchives_where
|
|
|
xiliml_getarchives_join
|
|
|
xiliml_modify_querytag
|
|
|
xiliml_taglink_append_lang
|
|
|
xiliml_link_append_lang
|
|
|
xili_nav_lang_list
|
usable to change the automatic insertion of languages list in navigation menu. Example:
/* tests */
function my_xili_nav_lang_list( $items, $args, $navmenu_check_option ) {
if ( $navmenu_check_option == $args->theme_location ) {
$end = xili_language_list( '<li>', '</li>', 'typenav', false ) ;
// langs list BEFORE
return $end.'<li class="menu-item menu-separator" ><a>|</a></li>'.$items; // class for display none... 1.8.9
} else {
return $items;
}
}
add_filter ('xili_nav_lang_list', 'my_xili_nav_lang_list', 10, 3); |
/* tests */
function my_xili_nav_lang_list( $items, $args, $navmenu_check_option ) {
if ( $navmenu_check_option == $args->theme_location ) {
$end = xili_language_list( '<li>', '</li>', 'typenav', false ) ;
// langs list BEFORE
return $end.'<li class="menu-item menu-separator" ><a>|</a></li>'.$items; // class for display none... 1.8.9
} else {
return $items;
}
}
add_filter ('xili_nav_lang_list', 'my_xili_nav_lang_list', 10, 3);
|
|
xili_nav_page_list
|
usable to change the automatic insertion of sub-selection of pages : see source
|
|
|
|
|
|
|
OTHER FILTERS
|
Some template tags inside WP core are not fully multilingual and need filters.
|
|
|
the_time
add_filter(‘the_time’,’my_date’,10,2);
|
Date management and translation are very complicated. Here by using a xili-language function, it is possible to modify the basic behaviour of the current template tag the_time.
|
function my_date($thetime,$theformat) {
/* param no used because php format */
return the_xili_local_time('%B %d, %Y - %H:%M',strtotime(get_the_time('m/d/Y H:i')));
}
add_filter('the_time','my_date',10,2); |
function my_date($thetime,$theformat) {
/* param no used because php format */
return the_xili_local_time('%B %d, %Y - %H:%M',strtotime(get_the_time('m/d/Y H:i')));
}
add_filter('the_time','my_date',10,2);
|
Post, Page
|
the_modified_time
add_filter(‘the_modified_time’,’my_modified_date’,10,2);
|
Date management and translation are very complicated. Here by using a xili-language function, it is possible to modify the basic behaviour of the current template tag the_modified_time.
|
function my_modified_date($thetime,$theformat) {
/* param no used because php format */
return the_xili_local_time('%B %d, %Y - %H:%M',strtotime(get_the_modified_time('m/d/Y H:i')));
}
add_filter('the_modified_time','my_modified_date',10,2); |
function my_modified_date($thetime,$theformat) {
/* param no used because php format */
return the_xili_local_time('%B %d, %Y - %H:%M',strtotime(get_the_modified_time('m/d/Y H:i')));
}
add_filter('the_modified_time','my_modified_date',10,2);
|
Post, Page
|
get_comment_date
add_filter(‘get_comment_date’,’my_comment_date’,10,2);
|
This is the date of each comments in the comments loop.
|
function my_comment_date($comment_time,$d = '') {
/* params no used because php format */
/* the first param is to be as msgid in .po example: %B %d, %Y - %H:%M or %B %d, %Y at %H:%M */
return the_xili_local_time('%B %d, %Y', strtotime(get_comment_time ('m/d/Y H:i')));
/* impossible to use get_comment_date as it is itself filtered*/
}
add_filter('get_comment_date','my_comment_date',10,2); |
function my_comment_date($comment_time,$d = '') {
/* params no used because php format */
/* the first param is to be as msgid in .po example: %B %d, %Y - %H:%M or %B %d, %Y at %H:%M */
return the_xili_local_time('%B %d, %Y', strtotime(get_comment_time ('m/d/Y H:i')));
/* impossible to use get_comment_date as it is itself filtered*/
}
add_filter('get_comment_date','my_comment_date',10,2);
|
Comments
|
|
|
|
|
|
|
|
|
© dev.xiligroup.com
|
2010
|
|
|
|
Ping : A way to keep the ?lang=xx_xx in the address bar with xili_language ? « Forums of xiligroup.dev
Ping : fatal error when calling xiliml_the_other_posts « Forums of xiligroup.dev
Ping : Arabic - not showing in xili-language 1.9.0 - and other (xili-dictionary) « Forums of xiligroup.dev
Ping : Extension xili-language : version 2.0 (compatible WP3.1) | xiligroup dev
Ping : calling the current language code « Forums of xiligroup.dev
Ping : Costume theme questions « Forums of xiligroup.dev
Ping : can I manage menu too? « Forums of xiligroup.dev
Ping : Today Q & R : language menu without navigation menu « Forums of xiligroup.dev
Ping : linked page « Forums of xiligroup.dev
Ping : Getting the current language « Forums of xiligroup.dev