Patrice Hollman
Patrice Hollman

Reputation: 31

Smarty gettext localization

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?

Upvotes: 3

Views: 2751

Answers (1)

Abid Hussain
Abid Hussain

Reputation: 7762

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.

Upvotes: 2

Related Questions