没有文本域的 WordPress 主题的本地化
我有一个没有文本域的 WordPress 主题(即 e(x) 而不是 e(x,domain))。我还在 /themes/My Theme/localization 下的文件夹中保存了 .po 和 .mo 文件(请注意我的主题中的空间名称)。我想激活 fr_FR。我创建了 fr_FR.po 和 .mo 并更改了 wp-config 以添加 fr_FR 的区域设置。然而,我仍然没有让法国人工作。我看到很多网站告诉你在functions.php 的顶部添加一个load_theme_textdomain,但我不知道我的textdomain 是什么。任何帮助将不胜感激。
优素福
I have a wordpress theme without textdomain (i.e. e(x) and not e(x,domain)). I also have the .po and .mo files in a folder under /themes/My Theme/localization (Notice the space name in the my theme). I would like to activate fr_FR. I created fr_FR.po and .mo and changed the wp-config to add the locale for fr_FR. However, I am still not getting the french to work. I saw many sites telling you to add a load_theme_textdomain at the top of functions.php, but I do not know what would my textdomain be. Any help will be appreciated.
Youssef
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使主题本地化正常工作,您需要检查主题并向每个
_e()
和__()
函数调用添加一个域。这:必须变成这样:
接下来,您需要在functions.php文件的顶部添加这段代码:
您可以阅读有关它的更多信息 在这篇文章中。
To get theme localization working, you're going to need to go through your theme and add a domain to every
_e()
and__()
function call. this:Will have to become this:
Next you'll need to add this bit of code at the top of your functions.php file:
You can read more about it in this post.
添加您自己的文本域。我最近对一个不是为本地化设计的主题做了这个,所以我发布了我所做的。
将其添加到functions.php
load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/languages' );
,其中
your-domain
可以是任何名称,但始终保持统一所有主题文件。现在浏览所有主题 PHP 文件,并执行以下操作:
如果您看到
_e('some text')
,则将其更改为_e('some text', 'your-domain' );
如果您看到
__('some text')
请将其更改为__('some text', 'your-domain');
如果您请参阅不带
__()
或_e()
的"some text"
,然后,如果使用
"some text"
在函数调用中,然后像上面一样使其__()
,包括文本域如果只是打印
"some text"
且不是任何函数调用的一部分,请将其包围使用如上所示的_e()
,并且不要忘记文本域。有关详细信息,请阅读 Wordpress 国际化和本地化指南。
Add your own text domain. I did this recently to a theme which was not designed for localization, so I'm posting what I did.
Add this to functions.php
load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/languages' );
where
your-domain
can be any name, but keep it uniform throughout all theme files.Now go through all the theme PHP files, and do the following:
If you see
_e('some text')
then change it to_e('some text', 'your-domain');
If you see
__('some text')
then change it to__('some text', 'your-domain');
If you see
"some text"
without__()
or_e()
then,If
"some text"
is used in a function call, then make it__()
like above, including the text domainIf
"some text"
is just printed and not part of any function call, surrround it with a_e()
like shown above, and don't forget the text domain.Read the Wordpress internationalization and localization guide for more information.
经过一长串令人难以置信的论坛,在一切正常的情况下执行如何设置它的相同步骤后,我终于找到了导致我出现问题的原因。
如果服务器在 WordPress 执行 bash 之前设置了全局
$locale
,则 WordPress 使用服务器的区域设置(在wp-includes/l10n.php
文件中,函数get_locale
)。我使用的解决方案是在定义 WPLANG 旁边设置全局 $locale...
After an unbelievably long string of forums going through the same steps of how to set it up when everything is working correctly, I finally found what was causing the issue for me.
If the server sets the global
$locale
before wordpress has a bash at it, then wordpress uses the server's locale settings (in thewp-includes/l10n.php
file, the functionget_locale
).The solution I used, is to set the global $locale right next to defining
WPLANG
...