gettext() usability problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

gettext() usability problem.

Post by jmut »

Ok gettext looks really nice and all (because translation takes place in a single place and you can use it in any environment).
But there are some usability problems that I see, and just cannot imagine this is really the case. Maybe I missunderstand something

Here is my test scenario:

Code: Select all

|-locale
| |-en_US
| | \-LC_MESSAGES
| |   |-messages.po
| |   \-messages.mo
| \-de_DE
|   \-LC_MESSAGES
|     |-messages.po
|     |-messages.mo
|     |-commonMessages.po
|     \-commonMessages.mo
|-templates
| \-index.html
|-templates_c
|-smarty.php
\-index.php

Code: Select all

//index.php

$locale = 'de_DE'; // Pretend this came from the Accept-Language header
$locale_dir = './locale'; // your .po and .mo files should be at $locale_dir/$locale/LC_MESSAGES/messages.{po,mo}



//header('Content-type: text/html; charset=utf-8');
echo  '<pre>';
//putenv("LANG=$locale");  //THIS DOES NOT WORK IF I TRY USING 'en' for example instead of 'en_US' (when renaming the directory of course)
setlocale(LC_MESSAGES, $locale);

$domain  = 'messages';
bindtextdomain($domain, $locale_dir);
bind_textdomain_codeset($domain,'UTF-8');
textdomain($domain);


echo gettext("Some text")."\n";
echo gettext("Some text2");

The issues I cannot resolve:

1. Using multiple 'domains' at once:
Usually there are some common strings. Like 'Yes', 'No', 'Submit' etc etc.
I would rather be able to load this from the same place for all my projects - I don't want to translate yes,no for each project. So the question is how can I use two "domains"...not sure this is the right terminology (meaning using two .mo files simultaniously). And of course if there are duplicates which one will take precedence?
2. Adding new msgid:
There are some tools like 'ngettext' to parse souce files and generate .po files out of these.
- How can I set to generate .po files for each language.. en_US, de_DE etc. without having to call it several times. I know I can write a script to do this but is kind of weird.
- And the more important thing....when I recreate the .po files...they all go blank...hence when I convert them to .mo I loose translation of stuff already translated. This is kind of wrong!

This is what bothers me for now...and kind of prevents me from using gettext :(
Post Reply