The internationalization (i18n) library for Angular
MIT License
Bot releases are visible (Hide)
Published by ocombe about 8 years ago
<a name"2.4.0">
Published by ocombe over 8 years ago
<a name"2.2.2">
Published by ocombe over 8 years ago
<a name"1.11.0">
Because of recent changes we have to use RxJS >= beta 2 and that means a recent version of Angular 2. You now have to upgrade to Angular beta 10 or more to use ng2-translate.
Published by ocombe over 8 years ago
<a name"1.10.0">
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
]
});