Recommandation on localization String in php
I wrote a simple php localization method:
function localizationString($key, $local){
if (!isset($local)){
$local = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
$arr = array("en" => array("aString" => "aString in English"),
"ja" => array("aString" => "aString in Japanese") );
$result = $arr[$local];
return $result[$key];
}
Every string which append to localization, I will use the loc开发者_Python百科alizationString call, like this:
echo ("Non-localization String with a localization String ".localizationString("aString", NULL));
Is there any recommandation for this method? Will there a problem if the array become very big? Is there a better way to make a better performance? Thank you.
Take a look at gettext for localization needs. You can use it like echo _("Hello World!");
and it will be translated to the language of choice.
精彩评论