I'm looking for a way to to do i18n and l10n.
I've used gettext
before and it was good: I would simply create .mo files in different languages and everything that needed to be translated would be in this notation:
echo __('string to be translated');
I know that there is Intl library built into PHP now, and I've been told that I should use it instead of gettext()
.
After reading through everything there is about Intl on php.net, I see that it has some nice features like locale handling, string comparison, number formatting, etc.
What I can't figure out is how I would handle regular string to string translation using Intl library. Any ideas?
Here's how I used intl for translations (tested on php v. 5.3.10 and 5.4.7):
intl.php
display.php
resource bundles
In the
locales
directory, I have my resource files:root.res - root language (English)
ja.res - Japanese
sp.res - Spanish
(etc)
That advise wasn't very truthful. The intl functions can be used in conjunction to gettext, not as replacement.
MessageFormatter
is what people have in mind when they associate INTL with text translations. The examples suggest so. But in reality it's just asprintf
on steroids. It injects numbers into existing strings. (I'm not even sure how the locale support is of any use there, as it just serves as internal switch.)You'd use gettext. Intl (like ICU underneath it) is for l10n, not loading translations.