我有两个问题需要在“运行时”更改主题的语言。我不确定我的问题标题,希望我的描述能有所帮助。
我已经使用了一个插件Polylang,它有很好的特性:链接内容相同但语言不同的页面,为每种语言配置主菜单,以及将添加到主菜单中的语言切换器。
(我也试过xLanguage和xili语言,但对我来说不太合适)
Polylang有很好的功能,但我还需要一些:
留言簿,它是一个像留言簿一样的页面,没有内容,只有评论。我需要两种语言的表单等(主题),但只有一个页面,我在页脚中有第二个菜单,我还想为每种语言使用不同的菜单元素(名称和链接),是否可以通过传递一些HTTP GET参数(和重定向)来更改语言,然后检查参数并用所需的语言更改/重新加载页面?
我已经试着改变wordpress_polylang
cookie中的值,但没有效果。我找到了load_theme_textdomain 但是没有参数来传递语言。
我使用Starkers主题,基于二十世纪十年代。
//编辑:我在核心中找到了这个片段。polylang插件的php,也许会有所帮助。
// NOTE: I believe there are two ways for a plugin to force the WP language
// as done by xili_language and here: load text domains and reinitialize wp_locale
// with the action \'wp\'
// as done by qtranslate: define the locale with the action \'plugins_loaded\', but
// in this case, the language must be specified in the url.
function load_textdomains() {
// sets the current language
if (!($this->curlang = $this->get_current_language()))
return; // something went wrong
// set a cookie to remember the language. check headers have not been sent to avoid ugly error
if (!headers_sent())
setcookie(\'wordpress_polylang\', $this->curlang->slug, time() + 31536000 /* 1 year */, COOKIEPATH, COOKIE_DOMAIN);
// set all our language filters and actions
$this->add_language_filters();
// our override_load_textdomain filter has done its job. let\'s remove it before calling load_textdomain
remove_filter(\'override_load_textdomain\', array(&$this, \'mofile\'));
// now we can load text domains with the right language
$new_locale = get_locale();
foreach ($this->list_textdomains as $textdomain)
load_textdomain( $textdomain[\'domain\'], str_replace($this->default_locale, $new_locale, $textdomain[\'mo\']));
// and finally load user defined strings (check first that base64_decode is not disabled)
if (function_exists(\'base64_decode\')) {
global $l10n;
$mo = new MO();
$reader = new POMO_StringReader(base64_decode(get_option(\'polylang_mo\'.$this->curlang->term_id)));
$mo->import_from_reader($reader);
$l10n[\'pll_string\'] = &$mo;
}
// reinitializes wp_locale for weekdays and months, as well as for text direction
global $wp_locale;
$wp_locale->init();
$wp_locale->text_direction = get_metadata(\'term\', $this->curlang->term_id, \'_rtl\', true) ? \'rtl\' : \'ltr\';
}