Adding translation in Wordpress Plugin

2019-08-01 03:01发布

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

and in my page I've just added the gettext like:

_("Hello")

My site is in italian so I will see "Ciao" but the plugin doesn't take the translation so I see still "Hello"

Can anyone help me ?

Thanks in advance

1条回答
太酷不给撩
2楼-- · 2019-08-01 03:23

With Wordpress you need to be using this format normally: either

_e( 'your_text_to_be_translated' );

or

__( 'your_text_to_be_translated' );
查看更多
登录 后发表回答