PDA

View Full Version : Dynamic Langauge Loading



pander
2 Aug 2010, 1:02 AM
Hi there,

I have an issue with regards to loading language files. My application allows the user to change the langauge and uses the same machanism as in the Dynamic Langauge example. However, this has presented me with a small problem which I have yet been unable to figure out.

When the user changes the language in the drop down this triggers a reload of the page as I also have to change other site furniture etc. and allow the locale to change. When the page reloads it pulls down the relevant language file. However, as per the dynamic example, this is done via ajax and so there is a period of time where the client is waiting for the language file from the server. Obviously this happens in an Ext.OnReady function but while the file is downloading the page continues to load. On the page may be an Ext component for example, and this component is wanting to create and initialise itself with strings from the new language file....but this may (or may not) have finished downloading yet and so I am getting intermittent errors because the string references are not always available.

How can I delay the initialisation of the component until after the langauge file has downloaded?

Kind Regards,
Paul.

Condor
2 Aug 2010, 1:15 AM
Call you application initialization code from the locale file request success handler (like the multi-lang example does in init -> onSuccess -> setupDemo).

pander
2 Aug 2010, 2:37 AM
Hi Condor,

Thank you for your reply.

One question though, isn't doing things that way a bit of a coding overhead because doesn't the function that gets executed after the file has finished loading have to be aware of ALL Ext components on the site? otherwise how does it know what page it's on and what to setup?

Regards,
Paul.

Condor
2 Aug 2010, 3:05 AM
You could avoid that by creating your own 'ready' event.
init.js

Ext.ns('My.namespace');
My.namespace.MessageBus = new Ext.util.Observable();
somefile.js

My.namespace.MessageBus.on('ready', function(){
// do stuff
});
otherfile.js

My.namespace.MessageBus.on('ready', function(){
// do other stuff
});
After loading locale file:

onSuccess: function(){
My.namespace.MessageBus.fireEvent('ready');
}

pander
2 Aug 2010, 3:28 AM
Hi Condor,

Thanks, makes sense now I see how you put that together, I will give it a try :)

Regards,
Paul.