chorme App 开发笔记-----本地化

============================================================
博文原创,转载请声明出处
电子咖啡(原id蓝岩)
============================================================
这一节我们介绍一下chorme App本地化问题--i18n。

在实现国际化,我们需要添加对应的国际化文件,最终整个文件结构图如下


新增了_locales文件夹存放多语言文件,messages.json存放对应key-value多语言文字信息。

我们过去的文字调用方法如下:


引入国际化后,调用方法如下:



那么怎么调用呢?”在manifest.json和css中,使用 “__MSG_messagename__”来调用相应的文字,如“__MSG_chrome_extension_name__”。

在js中,使用如下方法来调用

var message = chrome.i18n.getMessage("click_here", ["string1", "string2"]);//这里知多可以使用9个占位符

对于某些系统信息,chrome提供了相应的常亮,如 @@bidi_dir and @@ui_locale,详情如下:

Message nameDescription
@@extension_idThe extension ID; you might use this string to construct URLs for resources inside the extension. Even unlocalized extensions can use this message. 
Note: You can't use this message in a manifest file.
@@ui_localeThe current locale; you might use this string to construct locale-specific URLs.
@@bidi_dirThe text direction for the current locale, either "ltr" for left-to-right languages such as English or "rtl" for right-to-left languages such as Japanese.
@@bidi_reversed_dirIf the @@bidi_dir is "ltr", then this is "rtl"; otherwise, it's "ltr".
@@bidi_start_edgeIf the @@bidi_dir is "ltr", then this is "left"; otherwise, it's "right".
@@bidi_end_edgeIf the @@bidi_dir is "ltr", then this is "right"; otherwise, it's "left".


{
  "search_string": {
    "message": "hello%20world",		//具体的显示文字
    "description": "The string we search for. Put %20 between words that go together."	//注释文字,不会被用户看到
  },
  ...
}


对应的语言支持代号表如下

ar	Arabic
bg	Bulgarian
ca	Catalan
cs	Czech
da	Danish
de	German
el	Greek
en	English
en_GB	English (Great Britain)
en_US	English (USA)
es	Spanish
es_419	Spanish (Latin America and Caribbean)
et	Estonian
fi	Finnish
fil	Filipino
fr	French
he	Hebrew
hi	Hindi
hr	Croatian
hu	Hungarian
id	Indonesian
it	Italian
ja	Japanese
ko	Korean
lt	Lithuanian
lv	Latvian
nl	Dutch
no	Norwegian
pl	Polish
pt_BR	Portuguese (Brazil)
pt_PT	Portuguese (Portugal)
ro	Romanian
ru	Russian
sk	Slovak
sl	Slovenian
sr	Serbian
sv	Swedish
th	Thai
tr	Turkish
uk	Ukrainian
vi	Vietnamese
zh_CN	Chinese (China)
zh_TW	Chinese (Taiwan)


参见: https://code.google.com/chrome/extensions/i18n.html#overview-predefined



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值