Sencha touch Sencha本地化

Sencha touch Sencha本地化,sencha-touch,Sencha Touch,我需要在Sencha1.1.1上使用本地化 //app-en.js Locale = { title: 'hello' } //app-fr.js Locale = { title: 'salut' } 我的小组 var panel = new Ext.Panel({fullscreen: true, html: 'Text to locate'}); 如何检测语言并更改它 提前感谢。根据区域设置加载合适的javascript文件。查看或获取更好的想法 然后只需按以下方式使用代码: var

我需要在Sencha1.1.1上使用本地化

//app-en.js

Locale = {
title: 'hello'
}

//app-fr.js

Locale = {
title: 'salut'
}

我的小组

var panel = new Ext.Panel({fullscreen: true, html: 'Text to locate'});
如何检测语言并更改它


提前感谢。

根据区域设置加载合适的javascript文件。查看或获取更好的想法

然后只需按以下方式使用代码:

var panel = new Ext.Panel({
   fullscreen: true, 
   html: Locale.title
});

您希望使用替代对视图进行本地化。有关更多信息,请查看此网站:

和超控

Ext.define('MyApp.utils.nl.Main', {
    override: 'MyApp.view.Main',

    TAB_ONE_TITLE_SHORT: 'Hallo',
    TAB_ONE_TITLE: 'Hallo Sencha Touch 2',
    TAB_ONE_HTML: 'Deze app is geschreven in het Nederlands.',
});
也可以使用框架的loader类包含现有文件。在应用程序启动前将调用此命令:

将资源文件添加到app.json

"js": [
    {
      "path": "../touch/sencha-touch.js",
      "x-bootstrap": true
    },
    **{
      "path": "resources/translations/resources_nl.js",
      "remote": true
    },
    {
      "path": "resources/translations/resources_de.js",
      "remote": true
    },
    {
      "path": "resources/translations/resources_en.js",
      "remote": true
    },
    {
      "path": "resources/translations/resources_fr.js",
      "remote": true
    },**
    {
      "path": "app.js",
      "bundle": true,
      "remote": true
      /* Indicates that all class dependencies are concatenated into this file when build */
    }
],
我的用户可以选择一种语言,我将其保存到本地存储中。我的退路是英语。这里是我的app.js,我使用Ext.Loader类加载所需的语言文件

/*
 This file is generated and updated by Sencha Cmd. You can edit this file as
 needed for your application, but these edits will have to be merged by
 Sencha Cmd when it performs code generation tasks such as generating new
 models, controllers or views and when running "sencha app upgrade".

 Ideally changes to this file would be limited and most work would be done
 in other places (such as Controllers). If Sencha Cmd cannot merge your
 changes and its generated code, it will produce a "merge conflict" that you
 will need to resolve manually.
 */

Ext.Loader.setConfig({
    enabled: true,
    disableCaching: false
});

**Ext.Loader.syncRequire(['resources/translations/*'], function() {
    Resources = Resources[localStorage.getItem('language') || 'EN'].texts;
});**

Ext.application({
    name: 'MyApp',

    requires: [],

    models: [],

    stores: [],

    views: [],

    controllers: [],

    launch: function() {
        ...
    },

    onUpdated: function() {
        Ext.Msg.confirm(
            "Application Update",
            "This application has just successfully been updated to the latest version. Reload now?",
            function(buttonId) {
                if (buttonId === 'yes') {
                    window.location.reload();
                }
            }
        );
    }
});
下面是一个语言文件示例(参考资料/translations/resources_en.js):

此解决方案的优点是,您现在可以在视图中使用多语言文本声明:

Ext.create('Ext.Container', {
    renderTo: Ext.getBody(),
    items   : [
        {
            xtype: 'button',
            text : **Resources.generic.cancel**
        }
    ]
});
var Resources = Resources || {};

Resources.EN = {
    texts: {
        generic: {
            loading: "Load...",
            online: "Online",
            offline: "Offline",
            login: "Log in",
            logoff: "Log out",
            ...
        },
        list: {
            emptyText: "No elements have been found.",
            ...
        },
        map: {
            noMarkers: "There is no data to display on the map.",
            ...
        },
        settings: {
            scaleSize: "Scale screen?",
            ...
        },
        document: {
            openingDocumentFailed: "Opening document failed. Do you have an application that can open this type of document?",
            ...
        }
    }
}
Ext.create('Ext.Container', {
    renderTo: Ext.getBody(),
    items   : [
        {
            xtype: 'button',
            text : **Resources.generic.cancel**
        }
    ]
});