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 ever
Here's how I used intl for translations (tested on php v. 5.3.10 and 5.4.7):
namespace Example;
class Intl {
private $resource;
public function __construct() {
$bundle_location = "./locales";
$user_locale = \Locale::acceptFromHttp( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
$this->resource = new \ResourceBundle( $user_locale, $bundle_location );
}
...
use Example\Intl;
$intl = new Intl();
$r = $intl->resource;
echo $r['string_to_be_translated'];
...
In the locales
directory, I have my resource files:
root.res - root language (English)
root {
string_to_be_translated {String to be translated }
}
ja.res - Japanese
ja {
string_to_be_translated {\u5909\u63DB\u3055\u308C\u308B\u6587\u5B57\u5217 }
}
sp.res - Spanish
sp {
string_to_be_translated {Cadena a ser traducido }
}
(etc)