查看l10n后。php我找到了一种使用unload\\u textdomain函数切换textdomain的方法。
所以我创建了一个简单的开关
function switch_textdomain( $domain, $newLocale){
/*
This will only change the textdomain, not the locale.
It will only affect what kind of language will be used for the _e(), _(), __() commands for the $domain
*/
unload_textdomain( $domain );
/*mofile Folder
this may have to be changed depending on what you want to switch*/
$path = get_template_directory();
$mofile = "{$path}/{$newLocale}.mo";
return load_textdomain( $domain, $mofile );
}
这实际上不会更改区域设置,但只会更改指定域(主题或插件)的textdomain。
因为在我的情况下,我只需要翻译,这对我来说已经足够好了。