开发者

Recommandation on localization String in php

开发者 https://www.devze.com 2023-02-21 06:57 出处:网络
I wrote a simple php localization method: function localizationString($key, $local){ if (!isset($local)){

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消