我正在与一个运行英文WordPress的网站合作,但他们希望运行一个使用威尔士语言的插件。我们已经有了合适的。采购订单/。插件的mo文件,但当WordPress以英语运行时,它们不会被使用。是否有任何方法,可能是通过插件中的一些自定义PHP代码,我们可以强制WordPress仅为该插件使用威尔士语言文件,而将网站的其余部分保留为英语?
插件可以在与WordPress不同的语言中运行吗?
2 个回复
最合适的回答,由SO网友:ndm 整理而成
假设插件完全利用了本地化,例如,您可以尝试交换可能的load_plugin_textdomain
使用呼叫load_textdomain
您可以指向您喜欢的文件。
更干净的方法是使用plugin_locale
用于修改插件使用的区域设置的筛选器:
function my_plugin_locale_filter($locale, $domain)
{
if($domain === \'the_plugins_textdomain\')
{
return \'cy_CY\';
}
return $locale;
}
add_filter(\'plugin_locale\', \'my_plugin_locale_filter\', 10, 2);
这样,插件就可以或多或少安全地更新,而不会覆盖自定义代码。SO网友:vee
// to force use English, this filter value must return true.
add_filter(\'override_load_textdomain\', \'myPlugin_OverrideLoadTextDomain\', 10, 3);
add_filter(\'plugin_locale\', \'myPlugin_forceUseLanguageForCertainPlugin\', 10, 2);
function myPlugin_OverrideLoadTextDomain($override, $domain, $mofile) {
if ($domain === \'woocommerce\') {// change text domain from woocommerce to what you want.
$override = true;
}
return $override;
}
function myPlugin_forceUseLanguageForCertainPlugin($locale, $domain) {
if ($domain ==== \'woocommerce\') {// change text domain from woocommerce to what you want.
$locale = \'en_US\';// change your locale here to whatever you want.
}
return $locale;
}
需要2个过滤器挂钩才能工作。结束