1. #1
    Sencha User
    Join Date
    Mar 2011
    Posts
    18
    Vote Rating
    0
    Petitbomber is on a distinguished road

      0  

    Default Localization with json file

    Localization with json file


    Hello,
    I tried to implement a possibility to translate my Sencha Touch interface by putting the text in a json file.

    The solution with Ux.locale.Manager is too complicated for me (make myself the overriden of several components).
    Here is a proposal. I wait for your notes and improvements...

    In app.js :
    PHP Code:
    Ext.application({
        ...
        
    requires: [
        ...
        
    'myapp.util.locale'
        
    ],
    ... 
    The locale.js (in app/util):
    PHP Code:
    Ext.define('myapp.util.locale', {
        
    singletontrue,
        
    alternateClassName'locale',
        
    requires: ['Ext.Ajax'],
        
    config: {
            
    st""
        
    },
        
    constructor : function(config) {
                
    me=this;
                
    Ext.Ajax.request({
                           
    url'./resources/locales/lang.json',
                           
    async:false,
                           
    method'POST',
                           
    success: function(result){
                                
    me.config.st Ext.decode(result.responseTexttrue);
                                
    me.initConfig(config);
                                
    //me.callParent([config]);
                           
    },
                           
    failure: function(response) {
                                
    Ext.Msg.alert('Error localization');
                           }
            });
        }
    }); 
    An exemple of lang.json (in resources/locales):
    PHP Code:
    {
    "tabs": {
        
    "board"" Dashboard",
        
    "clocks""clocks"
    },
    "msg": {
        
    "loading"" loading",
        
    "error""Error"
    }

    And a use in panel :
    PHP Code:
    Ext.define("myapp.view.tablet.Main", {
    ...
    {
                
    xtype'myboard',
               
    titlelocale.getSt().tabs.board,
    ... 

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,074
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The reason the manager is more complicated as it supports changing the text dynamically. It started off something like what you're doing but would not work for changing text dynamically. The overrides aren't complicated, they are used because there are different ways of changing the text dynamically for different components. For example you do a setHtml method call on a Ext.Component but a setText on a Ext.Button.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2011
    Posts
    18
    Vote Rating
    0
    Petitbomber is on a distinguished road

      0  

    Default


    Hello,
    I agree with you. Your solution is more powerful than mine.
    It's just that I don't need to change the text dynamically and that the overrides is not complicated for you but difficult for me: I try it but I was fast discouraged...

    If you have advice to improve my method. It's welcome.

  4. #4
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    322
    Vote Rating
    4
    Scorpie is on a distinguished road

      0  
    I`m from Holland!

  5. #5
    Sencha User
    Join Date
    Mar 2011
    Posts
    18
    Vote Rating
    0
    Petitbomber is on a distinguished road

      0  

    Default


    Thanks.
    I will try that.

  6. #6
    Sencha User
    Join Date
    Mar 2011
    Posts
    18
    Vote Rating
    0
    Petitbomber is on a distinguished road

      0  

    Default


    I have test that i18n.bundle.touch solution.
    The old version have issues in MVC applications.
    The new version with css is great but you can't use it for fields (in placeholder, options...) and to translate text in a function.
    Too bad...

Thread Participants: 2