问题描述
我已经为wordpress创建了一个插件,现在我想翻译它.我在插件名称/语言环境"中添加了代码.po和.mo文件(我创建了语言环境"文件夹,在其中放置了de_DE,fr_FR,en_US,it_IT,es_ES,ru_RU文件夹)每个语言文件夹都包含一个名为"LC_MESSAGES"的文件夹,其中包含.po和.mo文件,例如"translation.mo and transolation.po"现在我要连接这些翻译.在我的配置文件中,我创建了以下内容:
I've create a plugin for wordpress and now I want translate it.I've adding in my code .po and .mo files in "Plugin-name/locale" (I've create "locale" folder where I put de_DE, fr_FR, en_US, it_IT, es_ES, ru_RU folders)Every language folder contains a folder called "LC_MESSAGES" containing .po and .mo file like "translation.mo and transolation.po"Now I want connect these translation.In my Config file I've created something like this:
$locale = str_replace("-", "_", $culture);
$textDomain = "translation";
try {
@putenv("LC_ALL=$locale");
}
catch (Exception $e) { }
setlocale(LC_ALL, $locale . ".utf8"); //Set language
bindtextdomain($textDomain, dirname(__FILE__) . "/locale"); //Specify location of translation tables
textdomain($textDomain); //Choose domain
在我的页面中,我刚刚添加了gettext,如:
and in my page I've just added the gettext like:
_("Hello")
我的网站是意大利语,所以我会看到"Ciao",但是该插件没有翻译,所以我仍然看到"Hello"
My site is in italian so I will see "Ciao" but the plugin doesn't take the translation so I see still "Hello"
有人可以帮助我吗?
预先感谢
推荐答案
使用Wordpress,您通常需要使用以下格式:要么
With Wordpress you need to be using this format normally:either
_e( 'your_text_to_be_translated' );
或
__( 'your_text_to_be_translated' );
这篇关于在Wordpress插件中添加翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!