WordPress-Timber-本地化失败

我在使本地化/翻译功能正常工作方面遇到困难。
我正在使用以下组件:

WordPress 4.4.2 Timber -> Twig

模板工作正常。只是localistaion似乎不起作用。
在我的研究过程中, 我在github上遇到了这篇文章, 因为他们没有透露任何有关如何设置的信息, 所以似乎并不完整… https://github.com/jarednova/timber/wiki/Text-Cookbook#internationalization
我最终使用了以下代码-由于某些原因, 该代码不起作用:
/functions.php
class StarterSite extends TimberSite {function __construct() { add_theme_support( 'post-formats' ); add_theme_support( 'post-thumbnails' ); add_theme_support( 'menus' ); add_theme_support( 'widgets' ); add_filter( 'timber_context', array( $this, 'add_to_context' ) ); add_filter( 'get_twig', array( $this, 'add_to_twig' ) ); add_action( 'init', array( $this, 'register_post_types' ) ); add_action( 'init', array( $this, 'register_taxonomies' ) ); $this-> register_theme_locals(); parent::__construct(); }function register_theme_locals(){ $path = get_template_directory() . '/languages'; $result = load_theme_textdomain('panther', $path ); if ( $result ) return; $locale = apply_filters( 'theme_locale', get_locale(), 'panther' ); die( "Could not find $path/$locale.mo" ); } . . .

/templates/base.twig
< button type="submit" class="btn btn-info"> < i class="fa fa-search"> < /i> {{__('Search', 'panther')}} < /button>

/languages/zh_CN.po
msgid "" msgstr "" "Project-Id-Version: Panther 0.1.20150828\n" "Report-Msgid-Bugs-To: http://webklex.com/support/theme/panther\n" "POT-Creation-Date: 2015-11-20 12:58:54+00:00\n" "PO-Revision-Date: Mon Feb 01 2016 21:29:54 GMT+0100 (CET)\n" "Last-Translator: admin < info@webklex.com> \n" "Language-Team: LANGUAGE < LL@li.org> \n" "Language: English\n" "Plural-Forms: nplurals=2; plural=n != 1\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-Basepath: .\n" "X-Poedit-SearchPath-0: ..\n" "X-Poedit-KeywordsList: _:1; gettext:1; dgettext:2; ngettext:1, 2; dngettext:2, 3; " "__:1; _e:1; _c:1; _n:1, 2; _n_noop:1, 2; _nc:1, 2; __ngettext:1, 2; __ngettext_noop:1, 2; " "_x:1, 2c; _ex:1, 2c; _nx:1, 2, 4c; _nx_noop:1, 2, 3c; _n_js:1, 2; _nx_js:1, 2, 3c; " "esc_attr__:1; esc_html__:1; esc_attr_e:1; esc_html_e:1; esc_attr_x:1, 2c; " "esc_html_x:1, 2c; comments_number_link:2, 3; t:1; st:1; trans:1; transChoice:1, 2\n" "X-Loco-Target-Locale: en_US\n" "X-Generator: Loco - https://localise.biz/"#: templates/base.twig:72 msgctxt "submit button" msgid "Search" msgstr "Search EN"

为了调试问题, 我转储了翻译。结果如下:
WordPress-Timber-本地化失败

文章图片
如果渲染视图/页面, 我仍然会得到未翻译的字符串:
WordPress-Timber-本地化失败

文章图片
我确实检查了是否已加载正确的语言, 是的。我什至检查了是否调用了正确的翻译函数(不是NOOP), 是的, 甚至调用了正确的函数。
我有点迷路了。因此, 如果有人知道我做错了什么或怎么回事, 请告诉我。
#1 只需简单的方法即可:
function panther_theme_setup() { load_theme_textdomain('panther', get_template_directory() . '/languages'); } add_action( 'after_setup_theme', 'panther_theme_setup' ); //this is recommended

对于编辑/更新语言文件, 我个人只是使??用” LOCO Translate” 插件, 因为这样我就不需要其他程序了。
【WordPress-Timber-本地化失败】资料来源:我, 但在这里:https://developer.wordpress.org/reference/functions/load_theme_textdomain/

    推荐阅读