我正在向上的小部件添加i18nList Category Posts. 我已经正确创建了pot文件,以及西班牙语和英语的po和mo文件。所有字符串都显示为_e()
在表单文件上。
目录结构如下:
/
include/
ListCategoryPostsWidget.php
lcp_widget_form.php
languages/
es_ES.mo
en_US.mo
plugin.php
还有其他文件,但这些是涉及翻译的文件。从我的Widget类(ListCategoryPostsWidget.php)中,我使用它来注册翻译:
$translation_dir = \'../languages\';
load_plugin_textdomain( \'list-category-posts\', null, $translation_dir );
这是我用来在ListCategoryPostsWidget中包含表单文件的代码。php文件:
/** @see WP_Widget::form */
function form($instance) {
include(\'lcp_widget_form.php\');
}
默认语言为英语,因此效果很好。但是,当我在WP配置中将WP\\u LANG设置为“es\\u es”时,我仍然可以在小部件上看到英文文本。有什么想法吗?
EDIT: 因此,我添加了更多代码:
<p><label for="<?php echo $this->get_field_id(\'title\'); ?>">
<?php _e("Title", \'list-category-posts\')?></label>
这就是我在lcp\\U widget\\u表单中使用\\u e函数的方式。php。
最合适的回答,由SO网友:Chip Bennett 整理而成
根据您的评论:
小部件生成的html?这只显示了函数中的字符串,例如:\\u e(“Category”)显示“Category”
我怀疑您没有正确配置翻译字符串。您需要包括textdomain 在每次转换字符串函数调用中,否则字符串将永远不会被转换。
e、 g.对于您的textdomain\'list-category-posts\'
:
_e( \'Category\' )
。。。应改为:
_e( \'Category\', \'list-category-posts\' )
确保所有翻译字符串函数都已相应声明。