sencha touch i18n基础知识

Rom*_*om1 7 internationalization sencha-touch

在Sencha touch中如何处理i18n?(我说的是对字符串的本地化支持,还有本地化组件的本地化支持)

一个更具体的问题:我有一个包含日期选择器的表单,当我使用法国安卓手机访问应用程序时,如何确保以欧洲格式显示和选择日期?

干杯

her*_*ano 8

尚未在SenchaTouch中使用i18n的官方API.虽然在Ext 4中有/ locale文件夹中所有组件的本地化文件.

有一个旧教程通过动态设置脚本标记的src属性来指示一种方法.

<script type="text/javascript" id="extlocale"></script>
<script type="text/javascript">

var browserLang = window.navigator.language; // get the browsers language
var locales = [ 'fr', 'es', 'pt', 'pt-BR', 'pt-PT' ]; // available locale files
var locale = 'fr'; // default locale

// check browser language against available locale files
for (var i = locales.length - 1; i >= 0; i--) {
    if (browserLang === locales[i]) {
        locale = browserLang;
        break;
    }
};

// Insert src attribute to extlocale
if(locale) {
    Ext.fly('extlocale').set({src:'ext/locale/ext-lang-' + locale + '.js'});
}

</script>
Run Code Online (Sandbox Code Playgroud)

使用window.navigator.language检查浏览器的语言.

必须在/ext/locale/ext-lang-fr.js
中设置区域设置文件.您可以在其中覆盖组件属性.

Ext.onReady(function() {

if(Date){
    Date.shortMonthNames = [
        "Janv",
        "Févr",
        "Mars",
        "Avr",
        "Mai",
        "Juin",
        "Juil",
        "Août",
        "Sept",
        "Oct",
        "Nov",
        "Déc"
    ];

    Date.getShortMonthName = function(month) {
        return Date.shortMonthNames[month];
    };

    Date.monthNames = [
        "Janvier",
        "Février",
        "Mars",
        "Avril",
        "Mai",
        "Juin",
        "Juillet",
        "Août",
        "Septembre",
        "Octobre",
        "Novembre",
        "Décembre"
    ];

    Date.monthNumbers = {
        "Janvier" : 0,
        "Février" : 1,
        "Mars" : 2,
        "Avril" : 3,
        "Mai" : 4,
        "Juin" : 5,
        "Juillet" : 6,
        "Août" : 7,
        "Septembre" : 8,
        "Octobre" : 9,
        "Novembre" : 10,
        "Décembre" : 11
    };

    Date.getMonthNumber = function(name) {
        return Date.monthNumbers[Ext.util.Format.capitalize(name)];
    };

    Date.dayNames = [
        "Dimanche",
        "Lundi",
        "Mardi",
        "Mercredi",
        "Jeudi",
        "Vendredi",
        "Samedi"
    ];

    Date.getShortDayName = function(day) {
        return Date.dayNames[day].substring(0, 3);
    };

    Date.parseCodes.S.s = "(?:er)";

    Ext.override(Date, {
        getSuffix : function() {
            return (this.getDate() == 1) ? "er" : "";
        }
    });
}

});
Run Code Online (Sandbox Code Playgroud)

我做了一个工作原型你可以在这里查看:http:
//lab.herkulano.com/sencha-touch/date-picker-i18n/