Oriesok Vlassky
Oriesok Vlassky

Reputation: 797

Server ignoring my setlocale settings

I am dealing with this problem quite a while and this is not my first question to it, but still I can not get localization to work correctly. I use WAMP server and php gettext. A simple code I made for demonstration of my problem:

 /* dirs */
 $directory = realpath('../locale');
 $domain = 'messages';

 /* trying to find out correct setting - last one is winner */
 $locale ="ro";             
 $locale ="ro_utf8";
 $locale ="ro_RO";
 $locale ="ro_RO.UTF-8";
 $locale ="Romanian_Romania.1250";  

 putenv("LANG=".$locale);

 print setlocale( LC_ALL, $locale);
 setlocale( LC_ALL, $locale);

 bindtextdomain($domain, $directory);
 textdomain($domain);
 bind_textdomain_codeset($domain, 'UTF-8');

 /* STRING TO BE TRANSLATED */
 echo _('string');

In ../locale directory there are many folders like this - $language_name/LC_MESSAGES/. These contain corresponding .po and . mo files with translations like this:

msgid "string"
msgstr "string SK"

in sk_SK folder or this

msgid "string"
msgstr "string RO"

in ro, ro_RO, ro_RO.UTF8, ro_RO.UTF-8, romanian, Romanian_Romania, Romanian_Romania.1250 folders.

And what document looks like:

Romanian_Romania.1250 string SK

So you can see clearly - I setlocale() to romanian, yet my text is translated using the translation in sk_SK directory. What am I doing wrong?

Are there some functions I could use to get informations about $locale strings and directory names my server expects to find?

Upvotes: 1

Views: 2075

Answers (2)

CodeNoob
CodeNoob

Reputation: 365

You can help :

locale -a

And you can whach the language exist in your computer.

 sudo locale-gen pt_PT
 sudo locale-gen pt_PT.utf8
 sudo update-locale

Upvotes: 0

Sergiu Costas
Sergiu Costas

Reputation: 560

try to do your code like this:

setlocale(LC_ALL, 'ro_RO','Romanian'); 

it had worked in my project

Upvotes: 1

Related Questions