Because Sencha Touch lacks an official way doing internationalization I'm writing my own small set of utility methods. I don't won't to embed another lib like jQuery to use already existing i18n plugins. At the moment I'm in trouble figuring out the best way. Currently I've a class implemented as a Singleton. In the constructor I determine the language and load the corresponding language file. At the moment I'm using Sencha methods and define a model and load the data (json) into a store. I think it's kind of convenient. Here a snippet from the constructor where I load the data:
Ext.define('Translation', {
extend: 'Ext.data.Model',
idProperty: 'key',
fields: [
{name: 'key', type: 'string'},
{name: 'translation', type: 'string'}
],
proxy: {
type: 'ajax',
url: 'res/translation-'+lang+'.json',
//appendId: false,
reader: {
type: 'json',
}
}
});
_store = Ext.create('Ext.data.Store', {
model : 'Translation',
autoLoad: true
});
The problem here is that the load is async (no way doing a synchronous call with sencha?!) which means that the application may start to load before this stuff is finished. I need the data because the views rely on it.
Ext.Loader.setConfig({enabled:true});
Ext.application({
name: 'MyApp',
controllers: ['Ctr1', 'Ctr2'],
models: ['Model1', 'Model2],
init: function() {
},
launch: function() {
}
});
The only solutions I've found so far would be
- use a callback and wrap the app initialization inside.
- Don't use Sencha and do the ajax request stuff manually.
- Don't use Ajax at all. Put translations for all languages into a javascript file, include it in index.html and make sure the utility class has access to the object.