Home:ALL Converter>Adding translation in Wordpress Plugin

Adding translation in Wordpress Plugin

Ask Time:2017-03-16T19:51:53         Author:Awkn

Json Formatter

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

Author:Awkn,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42833324/adding-translation-in-wordpress-plugin
yy