-
6 Mar 2013 5:22 AM #1
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 :
The locale.js (in app/util):PHP Code:Ext.application({
...
requires: [
...
'myapp.util.locale'
],
...
An exemple of lang.json (in resources/locales):PHP Code:Ext.define('myapp.util.locale', {
singleton: true,
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.responseText, true);
me.initConfig(config);
//me.callParent([config]);
},
failure: function(response) {
Ext.Msg.alert('Error localization');
}
});
}
});
And a use in panel :PHP Code:{
"tabs": {
"board": " Dashboard",
"clocks": "clocks"
},
"msg": {
"loading": " loading",
"error": "Error"
}
}
PHP Code:Ext.define("myapp.view.tablet.Main", {
...
{
xtype: 'myboard',
title: locale.getSt().tabs.board,
...
-
8 Mar 2013 6:10 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 436
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
8 Mar 2013 7:36 AM #3
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.
-
12 Mar 2013 1:36 AM #4
I`m from Holland!
-
16 Mar 2013 12:14 AM #5
-
17 Mar 2013 6:33 AM #6
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...


Reply With Quote