如果您努力翻译主题,您可能不希望将翻译的.po 和.mo 文件保留在父主题中,因为在更新主题时它们将被覆盖。最好的解决方案是将它们放在您的子主题中,这很容易做到,并且也在 WordPress CODEX 中进行了解释 。
所以基本上你只需要将你的语言添加到你的子主题中,然后使用 (添加到你的子主题的 functions.php) 以下函数从子主题而不是父主题加载它:
// Load translation files from your child theme instead of the parent theme
function wei_child_theme_locale() {
load_child_theme_textdomain( 'total', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wei_child_theme_locale' );
然后将翻译后的文件添加到子主题中的 「languages」 文件夹中。