2

I have problem with setlocale function in PHP 5.3 in Windows 7.

I need to set Russian locale with UTF-8 encoding. I saw some solutions where this is Russian_Russia.65001, but the function with this type of locale returns FALSE.

All solutions was designed for using in Windows XP where list of locales was in Control Panel. In Windows 7 this feature was removed.

andre487
  • 1,261
  • 2
  • 18
  • 27

2 Answers2

8

It's not possible to use UTF-8 locales on windows systems.:

If you provide a code page like UTF-7 or UTF-8, setlocale will fail, returning NULL.

Only windows code page Russian_Russia.1251 will work (see Moodle's table of locales).

You may still try set both and see which one comes trough:

if ($newLocale = setLocale(LC_CTYPE, 'ru_RU.UTF-8', 'Russian_Russia.1251'))
{
   echo 'Locale is now set to: ' . $newLocale;
}
piotr_cz
  • 8,755
  • 2
  • 30
  • 25
  • That little code is outcome of half of a day research :) I just hope Ms has solid reasons for not supporting UTF-8. It's 2013! – piotr_cz Apr 22 '13 at 07:46
3

This worked for me on Windows 7

putenv('LANG=fr_CA.UTF-8');
setlocale(LC_ALL,'fr_CA.UTF-8');
bindtextdomain('translation','./language');
bind_textdomain_codeset('translation','UTF-8');
textdomain('translation');

Path to .po/.mo files

./language -> fr_CA.UTF-8 -> LC_MESSAGES -> translation.po
./language -> fr_CA.UTF-8 -> LC_MESSAGES -> translation.mo
CloutsCa
  • 31
  • 2
  • 1
    Of course here fr_CA stands for French-Canadian (not Russian) – CloutsCa May 20 '14 at 18:56
  • 1
    Welcome to SO, and thanks for your answer. If you look at the question in more detail you'll notice that it's nearly 2 years old, and the author had already accepted answer that they felt answered their question adequately. This question has had nearly a thousand views, so you may be helping someone, sometime, with this, but really your focus is better spent on more recent questions. Again, thanks for your answer, it is appreciated, I'm just trying to guide you in your use of SO and involvement with the community. – Software Engineer May 20 '14 at 19:16