kawan16 / mithril-translate

Internationalization of your Mithril applications
http://kawan16.github.io/mithril-translate/
23 stars 0 forks source link

Async loading #2

Closed rosskhanas closed 9 years ago

rosskhanas commented 9 years ago

I have a question related to loading translations.

mx.translate.configure( { infix: './i18n/' , suffix: '.json' } ); mx.translate.use('en'); mx.translate('hey');

In this case, we asynchronously load a file with translations. But when we ask about a translation of a 'hey' word, an error happens, because a file is not loaded and 'translations' variable is undefined (or probably has old values if another language was initialized before. What do you think about idea of implementing something like promise pattern here, so we can get a callback for setting a new language?) Or how would you suggest to handle this case?

The only way I see is a manual .json file loading with callback and using mx.translate.use('en', object), but would be nice to have it handled inside the translation library.

kawan16 commented 9 years ago

Hi,

Thanks for your feedback. Indeed, it's a good idea and theres's no harm to do it. I will put it quickly.

kawan16 commented 9 years ago

Well, now the use function returns a promise. In this way, you can be sure the translation file has been loaded when you intends to translate !