如果您努力翻譯主題,您可能不希望將翻譯的.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」 資料夾中。