archer96/ng-i18next — pull request #52 by miiihi (2014-07-21 18:09:34+00:00)
Title: Dynamically load additional namespaces

I wanted to dynamically load additional namespaces.
Current version doesn't support that - if I add a namespace to ng-i18next options, it reinitializes the i18n, which means, that it reloads all namespaces... If I use window.i18next.loadNamespace() function, we get the same result, as window.i18n.loadNamespace(), changes the i18next options, which are by ref the same as ng-i18next options, which then triggers the reinitialization again.

To add the feature:
- I added the option to not watch options for changes
- added $q promises
- and added loadNamespace function.

My usage is now like this - set default options in any module config section:

$i18nextProvider.options = defaultOptionsObject;	// without any namespaces
$i18nextProvider.watchOptions = false;

In any controller or service...

$i18next.loadNamespace('myNamespace').then(function() {
console.log('Translation for myNamespace loaded');
}

On first loadNamespace() call i18next will be initialized, subsequent calls will just load additional namespaces... so every namespace is now loaded exactly once and, we get a promise of loading...