3

I am having trouble using gettext.

This is how I set locale:

  $lang = 'romanian';

  putenv("LANG=$lang");
  $smarty->assign('lang',$lang);

  setlocale(LC_ALL, $lang); 
  if (setlocale(LC_ALL, $lang)==false) print ' false'; else print setlocale(LC_ALL, $lang); 

  bindtextdomain("messages", realpath("../locale")); 
  textdomain("messages");

This prints Romanian_Romania.1250, so I suppose the setlocale function runs ok.

Examples from my .tpl files:

{_('Login')}:<br>
<b style="color:blue;">{$user.name}</b>
<br>
<a href="logout.php">{_('Logout')}</a>

I have created some folders with translations in \locale folder. sk_SK is for my default language - slovak and several for romanian, like: romanian, ro_RO, ro_RO.1250, Romanian_Romania, Romanian_Romania.1250. Each one of them contains a pot file with translations - \LC_MESSAGES\messages.pot.

What happens is: Any translation, that is in the folder sk_SK gets translated. If I rename the folders, I get everything translated correctly. But no mather what I do, no other folder is taken. I am dealing with this problem quite a while and I have tried several language settings and plenty different folder names.

Example 1:

in the sk_SK folder, I have pot file with translation for string 'Login' - 'SKSKSK'

in the ro_RO folder, I have pot file with translation for string 'Login' - 'RORORO'

in the browser I see 'SKSKSK'

Example 2:

in the sk_SK folder, I have pot file with translation for string 'Login' - 'RORORO'

in the ro_RO folder, I have pot file with translation for string 'Login' - 'SKSKSK'

in the browser I see 'RORORO'

I wonder if the problem has something to do with Smarty. Do you have any ideas?

  • about which folders did you speak ? "if I rename the folders, I get everything translated correctly. But no mather what I do, no other folder is taken." –  Sep 03 '12 at 14:46
  • \locale\sk_SK\LC_MESSAGES\messages.pot , \locale\ro_RO\LC_MESSAGES\messages.pot etc. – Patrice Hollman Sep 03 '12 at 14:48
  • I'm sorry i dont understand what you did ... What did you rename exactly ? What folders are not taken exactly ? and also what do you mean by "folders are not taken" ? –  Sep 03 '12 at 14:52
  • when you have changed of language did you clean your smarty cache ??? –  Sep 03 '12 at 15:11
  • I have tried to add $smarty->clearAllCache(); at the beginning of the localization php file. No effect. – Patrice Hollman Sep 03 '12 at 15:17
  • Also I have added another example. This is important - I can switch translations. I just always have to store the translation in the sk_SK folder. – Patrice Hollman Sep 03 '12 at 15:19
  • i think that smarty/php does not find the ro_RO folder at all, and the fallback is to use the default language. You should then check the name of the local that you set and then check that the folder exists too. –  Sep 03 '12 at 15:36
  • Well, the setlocale() function returns Romanian_Romania.1250. Is there a function I could use to get the prefered name of the folder for this localization? I mentioned several folders which are on the server but are ignored. – Patrice Hollman Sep 04 '12 at 07:40

1 Answers1

2

Read it and see below URL i think it is very help full to you.

What to use for localization (php/smarty/pear application)?

To be not dependant on the availability of the php extension, you should fall back to http://launchpad.net/php-gettext which provides a pure php implementation of gettext.

gettext has also the big advantage that dozens of tools exist that make it easy to translate those files.

Community
  • 1
  • 1
Abid Hussain
  • 7,724
  • 3
  • 35
  • 53
  • It looks like it's not a problem with using gettext or not ; but what's happened after he renamed the folders . I suppose it's a matter of cache but need details ;) –  Sep 03 '12 at 15:08
  • you see this url http://launchpad.net/php-gettext some example here you can download and compare your code. – Abid Hussain Sep 03 '12 at 15:18
  • I believe the code I have is working. I have also tried several small changes, still the situation is the same - my texts get translated using actual .po and .mo files in sk_SK directory. I can translate them into any language and pseudolanguage. As long as it is in the sk_SK directory. I just can not figure out why my system can not take the translation from any other directory, even though setlocale() function appears to be working. – Patrice Hollman Sep 04 '12 at 08:31