How to load a language using gettext in PHP?

I created a language file in poedit to use the gettext function of PHP, now on the page where I am trying to test it, I can not get it to find / load the .po or .mo file that I created, does anyone see what I'm doing wrong?

$locale = "en_US";
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("default", "/includes/locale");
textdomain("default");

//my .po ad .mo file is located here /includes/locale/en/default.mo

Although I am trying to load the default English file, I changed the text in the file to make sure that it reads from the language file, and currently it only shows the default text and does not translate, I think I wrong maybe

+3
source share
2 answers

, , , , , , - , , , .

FR

$locale = "fr_fr";
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("default", "/includes/locale");
textdomain("default");

bindtextdomain , - .po . - , /... , , 2- , LC_MESSAGES, LC_MESSAGES default.po.

, - , lang :

langfolder/ fr_FR/LC_MESSAGES/default.po

- , default.po , - , .po .mo, , , default , , , gettext -

+7

, .

"/includes/locale" ? -? : , . - :

  • C:/XAMPP/HTDOCS//_
  • //WWW//
  • // //
  • ..

, ?

+2

Source: https://habr.com/ru/post/1718109/


All Articles