Re: localisation in web applications
| From: | Leon Atkinson | Date: | Tue, 19 Dec 2000 22:35:36 +0000 |
| Subject: | Re: localisation in web applications | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31051@lists.php.net to get a copy of this message | ||
> How is gettext used? Do you create separate language profile files, that
are
> loaded up by gettext and passed to PHP?
Check out (http://www.gnu.org/software/gettext/gettext.html). That's the
home
page for the project.
Yes, Gettext uses separate files for each language. The files are
human-readable,
and can be edited with vi, emacs, whatever. There are command-line tools
for
manipulating the files, for merging change for example.
One cool thing is how the English phrase is the key to the translations.
You use
a function in your code to get a string appropriate for the local language.
And if
there's no matching phrase, the English phrase is returned. Here's an
example
(straight from my book):
<?
//set language to Spanish
putenv("LANG=es");
//specify location of translation tables
bindtextdomain("error_messages", "./locale");
//choose domain
textdomain("error_messages");
//print a test message
print(gettext("This book is named Core PHP Programming"));
?>
Essentially what's going to happen is that Gettext is going to look for
a file named es.po (or similar) in a directory called locale. If it finds
"This book is named Core PHP Programming" as a key, it will return
whatever's there ("Este libra..."). If not, it will just return they key.
That means you won't get weird messages like
ERROR_MESSAGE_123, and all the messages are in one language
inside the source code.
Of course, I should point out that langauges vary in word order. So,
when you have a phrase like, "There are %d items in your basket", you
have problems. The manual for Gettext talks about this a little bit,
and how to deal with it.
---
Leon Atkinson <http://www.leonatkinson.com/>