PDA

View Full Version : Multiple Languages



Angilo
6 Sep 2010, 6:49 AM
Hi everyone,

I'm working on a language module in my extjs application.
The application is supposed to be multilangual.

The language definitions are stored in the database. I thought of loading them into a jsonstore, then loading them into a global array, so the definitions can be accessed from all over the application (which is absolutely a must).

Somehow, the array is being filled after all other events. Which of course means the array is useless, since I need to use the definitions everywhere.

At the bottom you will find my code.

Thanks for your help!




var LanguageJsonStore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: '<?php echo base_url();?>index.php/language/listing/',
method: 'POST'
}),
root: 'results',
fields: [
{name: 'key', type: 'string', mapping: 'key'},
{name: 'value', type: 'string', mapping: 'value'}
],
listeners: {
load: {
fn: function(store, records, options){
LanguageArray[store.getAt(0).data.key] = store.getAt(0).data.value;
alert(LanguageArray['fax']); // alerts 'Fax Number'
}
}
},
autoLoad: true
});

alert(LanguageArray['fax']); // alerts undefined

Condor
6 Sep 2010, 6:53 AM
XHR request are asynchronous. You have to wait for the server to respond before you can use the data.

You will have to move all your code that uses LanguageArray to the LanguageJsonStore load event handler.

Angilo
6 Sep 2010, 7:20 AM
XHR request are asynchronous. You have to wait for the server to respond before you can use the data.

You will have to move all your code that uses LanguageArray to the LanguageJsonStore load event handler.

Ough, that's no option. Thanks for your info, that clears a lot. Do you have any other solution to load the language definitions dynamically? I thought a jsonstore would come out handy, because when the language definitions are edited, the store can be reloaded with the new definitions.

What do you suggest?

Condor
6 Sep 2010, 7:40 AM
You could make your server return javascript instead of JSON (code to create LanguageArray) and link to it in a <script> tag.