24 Aug 2011 12:50 AM #1
Unanswered: MVC with dynamic loading and... i18n ?
I would like to translate my ExtJS application in different languages. My issue is that I'm using ExtJS MVC framework, and most of my JS files are downloaded dynamically by the framework itself.
The ideal solution (that I thought of) would be to have an extra option in the Ext.Loader (or in my Ext.app.Application) that would define the language to use, and depending on this to automatically download such file as "a.MyClass.fr.js" after loading my "a.MyClass.js" (which would contain an Ext.apply, overriding my string resources). That's probably not available in the ExtJS framework at the moment.
The alternative solution I can see, is to perform a trick on the server-side. First, a cookie would be created on the client, to set to the language. On the server-side, I could catch all the requests to JS files, then if a cookie is set (='fr' for example), I'd combine the requested JS file (MyClass.js) with its i18n's friend (MyClass.fr.js) dynamically on the server and return the result. That would work, but it's really tricky because it implies other things (caching...).
Maybe the best way is to implement the first behavior I described in the ExtJS framework myself...
What do you think? I'm looking for a really clean and neat way of doing it! Thanks
24 Aug 2011 1:23 AM #2
If you want to dynamically download a file, and assuming the loader is enabled, you could do:
24 Aug 2011 1:40 AM #3
It's actually a test environment, I can + enjoy to use dynamic loading, and it's pretty convenient within the MVC framework as well. So that would be another issue / question
I could use Ext.require, but... with what? Where? I don't know when my file ("MyClass.js") is going to be loaded, and I need to apply my localization right after it (apply).
It would be nice to have an "afterload" listener on the Ext.Loader: I could then have a handler on it, which would actually call Ext.require with my localized filename ("MyClass.fr.js").
The hierarchy of folders within the MVC framework is quite strict and nice (controller / model / store / view...), but it would be nice to have a "i18n" folder that would be managed as well as the rest.
24 Aug 2011 1:53 AM #4
24 Aug 2011 5:19 PM #5
Mmm, I would have to add those "require" on all my classes then, manually. I could maybe create a patch (Ext.apply) on the Ext.Component (right before to create my Application), so that the constructor will check if there are any "require" to perform. Wouldn't be too hard and too dirty, isn't it?
25 Aug 2011 5:39 AM #6