0

I'm using PHP's gettext tool to translate a multilingual web app. It works fine on my local server, but not when hosting.

My directory structure for the locale .po and .mo messages

locale/
    ar_IQ/
        LC_MESSAGES/
            messages.mo
            messages.po
    ku_IQ/
        LC_MESSAGES/
            messages.mo
            messages.po

and my php code to set the locale

// get $locale from URL parameter or cookie
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "/locale");
textdomain("messages");
bind_textdomain_codeset('messages', 'UTF-8');

When changing locale to ar_IQ it works fine, but with ku_IQ the texts aren't translated at all.

I know there might not be a locale for ku_IQ on my hosting provider's servers, but shouldn't it still get the translated texts from the proper folder (i.e. ku_IQ)? Only date, time and other regional formats wouldn't work in that case.

mavili
  • 3,385
  • 4
  • 30
  • 46
  • possible duplicate of [Gettext doesn't translate](http://stackoverflow.com/questions/20482575/gettext-doesnt-translate) – deceze Mar 15 '14 at 09:58
  • but the answer doesn't solve my problem. because I don't have a locale for ku_IQ on my local server, still managing to show the translated texts. Like I said, only date and time formats aren't regional – mavili Mar 15 '14 at 10:01
  • If you don't have the locale installed, it shouldn't be working at all. Show the output of `locale -a` for both systems. – deceze Mar 15 '14 at 10:02
  • I checked, I don't have the locale on my system. I still get translated text, but not proper date and time format, which is what I'm expecting – mavili Mar 15 '14 at 10:10
  • For whatever reason it works on your local system... have you tried installing the locale on the server...?! – deceze Mar 15 '14 at 10:14
  • but I don't think I'll find a locale for ku_IQ. isn't there a way to just say use the texts from that folder, but leave other regional formats in the default locale? – mavili Mar 15 '14 at 10:16
  • Maybe not `ku_IQ`, I don't know. But at least `ku` needs to be installed. You may have to try to set the locale as `setlocale(LC_ALL, 'ku_IQ.UTF-8', 'ku_IQ', 'ku')` and see what sticks. The specifics can vary between different systems in my experience. – deceze Mar 15 '14 at 10:20
  • I checked the locales and I have resolved my problem by using a different version of the locale I require. how can I merge this question to the one you provided as possible duplicate? Or should I just delete this? – mavili Mar 15 '14 at 10:31
  • If you think it's appropriate, maybe you can edit my answer over there to add more details. This can be closed as full duplicate then. – deceze Mar 15 '14 at 10:36
  • I have added some notes on your answer. please check and confirm if you think it's appropriate. – mavili Mar 15 '14 at 10:45

0 Answers0