v1.10.0
<a name"1.10.0">
1.10.0 (2016-03-06)
Features
- MissingTranslationHandler: the MissingTranslationHandler is now able to return a value or an o (23267b13)
- TranslateService: onLangChange now returns a LangChangeEvent instead of an object (e3087ac7)
BREAKING CHANGES:
The methods setMissingTranslationHandler
, useLoader
and useStaticFilesLoader
have been removed. It was not a good practice to change these after DI. You should use provide
instead, during bootstrap or in the providers
property of your component.
If you don't need to change anything to the default configuration just use TRANSLATE_PROVIDERS
:
import {HTTP_PROVIDERS} from 'angular2/http';
import {TRANSLATE_PROVIDERS} from 'ng2-translate/ng2-translate';
import {bootstrap} from 'angular2/platform/browser';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
TRANSLATE_PROVIDERS
]);
If you need extra customisation you should use provide:
import {provide} from 'angular2/core';
import {HTTP_PROVIDERS} from 'angular2/http';
import {TranslateLoader, TranslateStaticLoader, TranslateService} from 'ng2-translate/ng2-translate';
import {bootstrap} from 'angular2/platform/browser';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
provide(TranslateLoader, {
useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
deps: [Http]
}),
// use TranslateService here, and not TRANSLATE_PROVIDERS (which will define a default TranslateStaticLoader)
TranslateService
]);
You can also use provide to define this at a component level, just add it to the providers
property of your application.
If you use Ionic 2, you can customize the service like this:
import {provide} from 'angular2/core';
import {TranslateService, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';
@App({
templateUrl: '....',
config: {},
providers: [
provide(TranslateLoader, {
useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
deps: [Http]
}),
TranslateService
]
});