Ti.Locale.getCurrentLanguage() , i18n 有何区别?
How Ti.Locale.getCurrentLanguage() , i18n defferent?
我的 Tianium 应用程序使用 i18n。
我在 i18n 下有四个文件夹。
en/ ja/ zh-CN/ zh-TW/
zh-CN是中国大陆使用的中文。
zh-TW是台湾使用的中文。
它适用于 i18n。
现在我想得到这个名字,在app.js。但是,至于Ti.Locale.getCurrentLanguage()
,台湾和大陆returns'zh'
.
如何区分是zh-CN还是zh-TW???
----解决办法----
感谢@DC Jmz
使用Ti.Locale.getCurrentLocale()
if ( Ti.Locale.getCurrentLocale().match(/zh-Hant/)) {
Ti.App.global.lang = 'zh-TW'; // taiwan letters
}
if ( Ti.Locale.getCurrentLocale().match(/zh-Hans/)) {
Ti.App.global.lang = 'zh-CN'; // mainland china letters
}
尝试使用 Ti.Platform.getLocale()
System's default language.
Locale, as a combination of ISO 2-letter language and country codes. For example, en-US or en-GB. See the ISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference.
我的 Tianium 应用程序使用 i18n。 我在 i18n 下有四个文件夹。
en/ ja/ zh-CN/ zh-TW/
zh-CN是中国大陆使用的中文。
zh-TW是台湾使用的中文。
它适用于 i18n。
现在我想得到这个名字,在app.js。但是,至于Ti.Locale.getCurrentLanguage()
,台湾和大陆returns'zh'
.
如何区分是zh-CN还是zh-TW???
----解决办法---- 感谢@DC Jmz
使用Ti.Locale.getCurrentLocale()
if ( Ti.Locale.getCurrentLocale().match(/zh-Hant/)) {
Ti.App.global.lang = 'zh-TW'; // taiwan letters
}
if ( Ti.Locale.getCurrentLocale().match(/zh-Hans/)) {
Ti.App.global.lang = 'zh-CN'; // mainland china letters
}
尝试使用 Ti.Platform.getLocale()
System's default language.
Locale, as a combination of ISO 2-letter language and country codes. For example, en-US or en-GB. See the ISO 639-1 and ISO 3166-1 alpha-2 sections of wikipedia for reference.