【问题标题】:How do I check which language file (.mo) is being used for my Wordpress (Woocommerce) child theme?如何检查我的 Wordpress (Woocommerce) 子主题正在使用哪种语言文件 (.mo)?
【发布时间】:2018-03-27 07:46:00
【问题描述】:

我知道这已经被问过很多次了,但我还没有找到适合我的情况的解决方案。我一直在猜测这个问题,因为我不知道如何检查正在加载的 .mo 文件。

我在设置中将 wordpress 设置为我的语言,在 my-theme/languages 中设置了一个已翻译的 .mo 文件,在我的 functions.php 文件中设置了以下函数:

add_action( 'after_setup_theme', 'my_child_theme_setup' );
function my_child_theme_setup(){
    load_child_theme_textdomain( '[text-domain]-language', get_stylesheet_directory_uri() . '/languages' );
}

我尝试了不同的目录、文本域,甚至用一个全新的文件替换了 .mo 文件以防万一,但到目前为止似乎没有任何效果。

任何关于我可能做错的帮助或关于调试的建议将不胜感激!

【问题讨论】:

    标签: php wordpress translation


    【解决方案1】:

    在functions.php文件中设置文件夹路径:

    load_theme_textdomain('my-theme', get_template_directory().'/languages');
    

    请记住,mo 文件必须具有正确的名称。例如:en_US 表示英语。 如果要检查当前语言检查:How to determine the current language of a wordpress page when using polylang?

    【讨论】:

    • 我使用 get_stylesheet_directory_uri() 的原因是因为 get_template_directory() 检索父主题的路径而不是子主题。我还确保我的 .mo 文件具有正确的名称。
    猜你喜欢
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 2022-09-23
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多