没有textdomain的wordpress主题的本地化

sem*_*you 1 wordpress themes localization

我有一个没有textdomain的wordpress主题(即e(x)而不是e(x,domain)).我还将.po和.mo文件放在/ themes/My Theme/localization下的文件夹中(注意我主题中的空格名称).我想激活fr_FR.我创建了fr_FR.po和.mo并更改了wp-config以添加fr_FR的语言环境.但是,我仍然没有让法国人工作.我看到许多网站告诉你在functions.php的顶部添加一个load_theme_textdomain,但我不知道我的textdomain会是什么.任何帮助将不胜感激.

优素福

Pat*_*Pat 6

为了获得主题本地化工作,你将需要经过你的主题和域添加到每一个_e()__()函数调用.这个:

_e('some text');
__('some other text');
Run Code Online (Sandbox Code Playgroud)

必须成为这个:

_e('some text', 'your-domain');
__('some other text', 'your-domain');
Run Code Online (Sandbox Code Playgroud)

接下来,您需要在functions.php文件的顶部添加这段代码:

load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/localization' );

$locale = get_locale();
$locale_file = TEMPLATEPATH."/localization/$locale.php";
if (is_readable($locale_file))
    require_once($locale_file);
Run Code Online (Sandbox Code Playgroud)

您可以在这篇文章中阅读更多相关信息.


Dhe*_*mar 5

添加您自己的文本域.我最近做了一个不是为本地化而设计的主题,所以我发布了我所做的.

将其添加到functions.php中

load_theme_textdomain( 'your-domain', TEMPLATEPATH.'/languages' );

where your-domain可以是任何名称,但在所有主题文件中保持统一.

现在浏览所有主题PHP文件,并执行以下操作:

如果您看到_e('some text')然后将其更改为_e('some text', 'your-domain');

如果您看到__('some text')然后将其更改为__('some text', 'your-domain');

如果你看"some text"不到__()_e()那么,

如果"some text"在函数调用中使用,__()则按上面的方式进行,包括文本域

如果"some text"只是打印而不是任何函数调用的一部分,请使用_e()上面显示的内容覆盖它,并且不要忘记文本域.

阅读Wordpress国际化和本地化指南以获取更多信息.