palm基础----8 国际化

 

strings.json 中数据是以 key = value 的格式存储的,类似于java中的.properties文件

在 resources 目录下创建 ${languageCode} - ${countryCode}

Mojo.Locale.strings变量中存放了与当前 系统(国家-语言)有关的strings.json的信息,是一个JSON变量。

也可以这样获取 该JSON 变量,这样就可以取任意的 *.json文件名了。

var value= Mojo.Locale.readStringTable("strings.json""zh_cn");

 

如果要读取 国际化文件中 的值

方式(1):

Mojo.Locale.strings.key

        它只能读取与当前系统相关联语言的 系统默认资源文件(strings.json) 中的值

 

方式(2):

Mojo.Locale.readStringTable("strings.json""zh_cn").key

        它可以读取任意语言版本 任意资源文件名称 中的值

 

资源文件中带有变量,如,strings.json 中:

welcome = Hello, #{name} say : #{words}

 

则:

var    welcome  =  $L(“welcome”);
//     welcome  =  Mojo.Locale.strings.welcome;
//
     welcome  =  Mojo.Locale.readStringTable("strings.json", "en_us").welcome;
var    tmp      =  new   Template(welcome);
var    value    =  tmp.evaluate( { 'name' : 'nami',  'words' : 'Hello world!!!' } );
Mojo.Log.info( value );

 

 

 

posted on 2011-01-19 23:36  TroyZ  阅读(189)  评论(0编辑  收藏  举报