我试图避免在我的网站上安装一个成熟的多语言插件,我几乎做到了。
只有一件事,我需要控制这个插件是否——WP-Members – 是否按每页进行翻译。
默认语言为挪威语,所有属于/英语/的子页面都会自动设置为英语(使用this method). 插件正在使用。采购订单/。mo文件,但更改html代码不会使插件更改其语言。
是否有可能以某种方式欺骗插件,使其认为博客是用另一种语言写的?
我试图避免在我的网站上安装一个成熟的多语言插件,我几乎做到了。
只有一件事,我需要控制这个插件是否——WP-Members – 是否按每页进行翻译。
默认语言为挪威语,所有属于/英语/的子页面都会自动设置为英语(使用this method). 插件正在使用。采购订单/。mo文件,但更改html代码不会使插件更改其语言。
是否有可能以某种方式欺骗插件,使其认为博客是用另一种语言写的?
是的,有点像。任何本地化插件(如WP Members)都会脱离WordPress设置的“语言环境”。可以使用locale
滤器但也可以使用plugin_locale
请参见:https://developer.wordpress.org/reference/hooks/plugin_locale/
使用plugin_locale
特定于插件*的文本域(在本例中为“wp members”)
add_filter( \'plugin_locale\', \'my_plugin_locale_filter\', 10, 2 );
function my_plugin_locale_filter( $locale, $domain ) {
// If the text domain is \'wp-members\'
if ( \'wp-members\' == $domain ) {
/*
* This logic adapted from the method you referenced at
* http://beta.beantin.se/wordpress-setting-language-individual-pages/
* Note that the function get_top_parent_page_id() from that example
* is used here, and the logic is not adapted to your specific
* question (i.e. I assume the default $postLanguage value is
* Norwegian in your case and you are switching it to English) so
* change this to match what you are doing with the other elements
* being used from that process.
*/
$postLanguage = "en-GB";
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "565") { // ID of the "på svenska" page
$postLanguage = "sv";
}
$locale = $postLanguage;
}
}
// Always return the value being filtered.
return $locale;
}
*任何插件的文本域都应在插件主文件的标题中注明。例如,如果打开wp成员。php并查看插件标题,您将在标题“文本域:”下找到它。我在本地主机(WAMP)上安装了以我当前语言(pt\\U BR)编写的新版本WordPress。登录后,WordPress告诉我存在翻译更新。我单击进行更新,出现以下消息:Atualizando traduções de WordPress (pt_BR)… O pacote não pôde ser instalado. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature 翻