Xili-language toolbox in one table

In this table, all the main widgets, template tags, functions and hooks are grouped. (March 2015: under finishing and pending review step from previous version in 2010 đŸ˜‰ ).It is recommended to read the source of the most recent version. Functions are grouped at end of the source.
It is a summary of the “technical” features of xili-language plugin and is dedicaced to webmaster and theme’s designer.

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)
Widget Languages List
Widget Languages List
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
Widget Recent comments list
Widget Recent comments list
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 namedList of recent posts
multiple widgets possible with different languages (fixed or dynamic)
Widget List of recent posts
Widget List of recent posts
TEMPLATE TAGS usable by theme’s designer and webmaster Theme
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
default parameters:
($before = ‘<span class=”xili-lang”>(‘, $after =’)</span>’)
in loop display the language of the post Useful inside a multilingual category loop.
loop, category, search
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)

    ','','siderss'); } ?>
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.
post – page – loop
default parameters:
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.
Search form with language selectors
Search form with language selectors

 * define when search form is completed by radio buttons to sub-select language when searching
function special_head() {
    if ( class_exists('xili_language') ) {  // if temporary disabled
        // to change search form of widget
        // if ( is_front_page() || is_category() || is_search() )
        if ( is_search() || is_404() ) {
            add_filter('get_search_form', 'my_langs_in_search_form_2015', 10, 1); // here below
add_action( 'wp_head', 'special_head', 11) ;
 * add search other languages in form - see functions.php when fired
function my_langs_in_search_form_2015 ( $the_form ) {

    $form = str_replace ( '', '', $the_form ) . '' . xiliml_langinsearchform ( $before='', $after='', false) . '';
    $form .= '';
    return $form ;
search – sidebar
FUNCTIONS usable by developer with knowledges in php (see php source) CMS
the_curlang() deprecated replaced by xili_curlang()

/*as used in child of twenty fifteen */
if ( isset ( $xili_theme_options['xl_header'] ) && $xili_theme_options['xl_header'] ) {
                global $xili_language, $xili_language_theme_options ;
                // check if image exists in current language
                // 2013-10-10 - Tiago suggestion
                $curlangslug = ( '' == xili_curlang() ) ? strtolower( $xili_language->default_lang ) : xili_curlang() ;
default parameters:
($format=’%B %d, %Y’,$time = null)
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()); ?>
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.

  • ?
  • ?

Another example :

  • ?
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: */
 $r = new WP_Query($thequery);
loop, custom queries
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
(Cette page en français)
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)
add_action (‘xiliml_the_category’,’your_xiliml_the_category’,10,3)
template tag
template tag
template tag
In this example described formerly, the list of languages is enriched by flags:

function my_xili_language_list($before = '
  • ', $after ='
  • ',$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 ."description,THEME_TEXTDOMAIN)."'>"." slug.".png' alt='' />".$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=='
  • ') { if (the_curlang() == $language->slug) { $beforee = '
  • '; } else { $beforee ='
  • '; } } $a .= $beforee ."description,THEME_TEXTDOMAIN)."'>"." slug.".png' alt='' /> ". __('in '.$language->description,THEME_TEXTDOMAIN) ."".$after; } } if (is_category()) { $currenturl = xiliml_get_category_link(); $a .= $before.""." ".__('in all languages',THEME_TEXTDOMAIN)."".$after; } echo $a; } } add_action('xili_language_list','my_xili_language_list',10,3);
  • template tag
    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 .") ";
            else :
                $new_cat_name =  $content;
            return $new_cat_name;
    wp list categories
    header xhtml
    add_filter(‘head_language_attributes’,’my_ head_language_attributes’,1,1);
    header xhtml
    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)
    xiliml_single_cat_title_translate used by filter for wp_title() tags – since 1.4.1
    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( '
  • ', '
  • ', 'typenav', false ) ; // langs list BEFORE return $end.''.$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.
    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')));
    Post, Page
    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')));
    Post, Page
    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*/
    © dev.xiligroup.com 2010 – 2015-03