Sencha-touch localization. Use a store or a global JSON object?

送分小仙女□ 提交于 2020-01-04 06:45:07

问题


I'm writting an application in Sencha-Touch 1.1 and I want to add localization to strings.

I've thought (but not implemented) of two ways.

  1. Create seperate JSON files for each language (en-US.json, el-GR.json etc) and use a proxy and a store to load the data, changing each time the proxy url (json file destination). The problem is that I don't know how to extract the data from the store afterwards.

  2. Create a global JSON object which then I inflate (parse the json file and turn it into an object). The problem here is that I cannot seem to find a way to parse a JSON file without using a reader/proxy combo.

Is there any optimal solution for localizing strings in sencha-touch?


回答1:


A common approach is to extract all of your strings into class level properties and have separate locale files which override these classes and their string properties.

For example, if I had a panel like this:

MyApp.MyPanel = Ext.extend(Ext.Panel, {

    myPanelContent: 'This is your text to be translated...',

    initComponent: function(){

        Ext.apply(this, {
            html: this.myPanelContent
        });

         MyApp.MyPanel.superclass.initComponent.call(this)
    }

});

And then you would have a locale file along the lines of:

Ext.override(MyApp.MyPanel, {

    myPanelContent: 'This is a translation of my text to another language'

});

You can then either load the correct locale file when your app is loaded (after the views themselves have been loaded) or dynamically load the locale files during runtime (this would require logic to update each of the views with the current value).

Hope this makes sense, give me a shout if it doesn't!

Stuart



来源:https://stackoverflow.com/questions/8226173/sencha-touch-localization-use-a-store-or-a-global-json-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!