Tag: WPML

  • String translation not working when do wordpress Ajax with WPML

    String translation not working when do wordpress Ajax with WPML

    正常的配置 WPML 使用 PO/MO 文件 使用 Codestyling Localisation 创建 PO/MO 文件 问题是在时候 Ajax 的时候,函数 __() 失效, 因为,首先你需要加载所有关于当前语言的翻译。很奇怪的 WPML 不能正确的使用翻译文件,这可能是 WORDPRESS 和 WPML 的一些限制。暂时的,下面的方法可能对大家有些帮助。 如果你做一个搜索的功能,首先,添加一个隐藏域到表单里: if(defined(‘ICL_SITEPRESS_VERSION’) && defined(‘ICL_LANGUAGE_CODE’)){ echo ‘<input type=”hidden” id=”lang” name=”lang” value=”‘.ICL_LANGUAGE_CODE.'” />’; } 在 Ajax call: if(!empty($_REQUEST[‘lang’])) { global $sitepress; $sitepress->switch_lang($_REQUEST[‘lang’], true); $lang = get_template_directory() . ‘/language’; $unload = unload_textdomain(‘textdomain’); $load = load_textdomain(‘textdomain’, $lang…

  • WPML:Get posts also available in other languages

    WPML:Get posts also available in other languages

    文章页面里,在文章的底部显示该篇文章对应的翻译的语种(国旗)和标题。 暂时没有发现有现成的函数或 API 接口。但是从WPML 的表里面不难看出他们的关系,通过一句SQL即可找出当前文章对应文章的ID, 如下: function _post_foot_languages(){ global $post, $wpdb, $sitepress; $active_languages = $sitepress->get_active_languages(); unset($active_languages[ICL_LANGUAGE_CODE]); //print_r(array_keys($active_languages)); $source_language_code = “”; if(ICL_LANGUAGE_CODE != $sitepress->get_default_language()) $source_language_code = ” and source_language_code = ‘”.$sitepress->get_default_language().”‘”; $query =” SELECT * FROM {$wpdb->prefix}icl_translations WHERE trid = ( SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id = {$post->ID}{$source_language_code}) AND language_code in (‘”.join(‘\’,\”,array_keys($active_languages)).”‘)”; //AND language_code !=…

  • wpml translate blogroll Link categories

    我没有找到更好的办法,后来想了另一个办法: 由于WPML 是可以翻译widget title 的,所以我新建一个 blogFoll 的widget,可以填写标题,选择想要显示的分类。 直接粘贴到主题文件的functon.php 里即可。 if (!class_exists(‘LinksList_Widget’)) : class LinksList_Widget extends WP_Widget { const LANG = ‘yaocms’; function __construct() { $widget_ops = array( ‘classname’ => strtolower(get_class($this)) ); $control_ops = array(‘id_base’ => strtolower(get_class($this))); $this->WP_Widget(strtolower(get_class($this)), __(‘Links List Widget’, self::LANG), $widget_ops, $control_ops); } function widget($args, $instance) { extract($args); /* User-selected settings. */ $title =…

  • 让 jQuery Datepicker 兼容 WordPress 和 WPML

    让 jQuery Datepicker 兼容 WordPress 和 WPML

    没什么好说的,直接代码: jQuery(function($){ $.datepicker.regional[‘zh-hans’] = $.datepicker.regional[‘zh_CN’] = { closeText: ‘关闭’, prevText: ‘&#x3c;上月’, nextText: ‘下月&#x3e;’, currentText: ‘今天’, monthNames: [‘一月’,’二月’,’三月’,’四月’,’五月’,’六月’, ‘七月’,’八月’,’九月’,’十月’,’十一月’,’十二月’], monthNamesShort: [‘一’,’二’,’三’,’四’,’五’,’六’, ‘七’,’八’,’九’,’十’,’十一’,’十二’], dayNames: [‘星期日’,’星期一’,’星期二’,’星期三’,’星期四’,’星期五’,’星期六’], dayNamesShort: [‘周日’,’周一’,’周二’,’周三’,’周四’,’周五’,’周六’], dayNamesMin: [‘日’,’一’,’二’,’三’,’四’,’五’,’六’], weekHeader: ‘周’, dateFormat: ‘yy-mm-dd’, firstDay: 1, isRTL: false, showMonthAfterYear: true, yearSuffix: ‘年’}; $.datepicker.setDefaults( $.datepicker.regional[ “<?php echo defined(‘ICL_LANGUAGE_CODE’)?ICL_LANGUAGE_CODE:WPLANG;?>” ] ); }); 最后一行,这儿由于 WPML 和 WORDPRESS 的语言静态变量不一样,值也不同,需要判断然后输出,输出的值可能是 zh-hans,或 zh_CN,所以在第一行声明了两个变量来存储翻译。

  • How to make Popularity Posts Widget compatible with WPML

    How to make Popularity Posts Widget compatible with WPML

    In table $prefix_PopularityPostsWidget  The view record store here like this: There is WPML function wpml_get_language_information can get the post language information by post id, like this wpml_get_language_information($post->ID)   Array ( [locale] => fr_FR [text_direction] => [display_name] => Français [native_name] => Français [different_language] => ) Array ( [locale] => en_US [text_direction] => [display_name] => Anglais [native_name] => English [different_language] => 1 ) If it’s different language, the value will be true (1) Depand on this, now we can modify public function widget in class_popularity-posts-widget.php Inside function widget, find loop foreach ($rows as $row) Replace by the code between: ////////////// Loop /////////////////// foreach ($rows as $row) { } ////////////// End of loop…

  • Simple WPML language switch

    Simple WPML language switch

    公司客户老喜欢吧 语言选择器 做成这样~ 麻烦~ function icl_post_languages(){ $languages = icl_get_languages(‘skip_missing=0&orderby=code’); if(1 < count($languages)){ $langs[] = ‘<div class=”languages”>’; foreach($languages as $l){ if($l[‘language_code’] == ‘zh-hans’) $l[‘language_code’] = “中文”; $active = $l[‘active’] == 1?”class=’active_language'”:””; $langs[] = ‘<a ‘.$active.’ href=”‘.$l[‘url’].'”>’.$l[‘language_code’].'</a>’; } $langs[] = ‘</div>’; echo join(“\n”, $langs); } } 文章( Post)和 分类目录(category)页面不显示多语言选择链接 if (icl_post_languages()): $post_types=get_post_types(array( ‘public’ => true, ‘_builtin’ =>…

  • icl_link_to_element and icl_object_id

    icl_link_to_element and icl_object_id

    Example usage Example Purpose Produced HTML <?php icl_link_to_element(10); ?> Link to page 10 (support page) <a href=”/support/”>Support</a> <?php icl_link_to_element(10,’post’,__(‘Get help’)); ?> Link to support page with an alternative link text <a href=”/support/”>Get help</a> <?php icl_link_to_element(10,’post’,false, array(‘category’=>’products’,’priority’=>’high’); ?> Link to support page and add two arguments <a href=”/support/?category=products&amp;priority=high”>Support</a> <?php icl_link_to_element(10,’post’,false,’priority’=>’high’,’faq’); ?> <?php icl_link_to_element(3,’tag’); ?> Link to…

  • WPML Coding API and Custom Language Switcher

    WPML Coding API and Custom Language Switcher

    老是打不开这些页面,干脆复制到自己的地盘来了。方便自己也方便大家。 神马?WPML 是啥,自己百度吧! WPML offers functions that can be used in your WordPress theme to provide correct support for multilingual themes. Function Purpose Notes do_action(‘icl_language_selector’) Insert the drop down language selector. Described in the language setup section of the getting started guide. do_action(‘icl_navigation_menu’) Insert the top navigation menu. Described in the navitaionsection of the getting started guide. do_action(‘icl_navigation_breadcrumb’)…