0.0.7 • Published 5 years ago
@medrecord/frontend-translations-middleware v0.0.7
Medrecord Translations Middleware
This is a translation middleware for loading and using translations.
Installation
Add TranslateModule from @ngx-translate/core.
It requires HttpClientModule.
app.module.ts
@NgModule({
...
imports: [
...
HttpClientModule,
TranslationMiddlewareModule.forRoot(),
})
...
],
...
})
export class AppModule { }Usage
Inject TranslationMiddlewareService into your component.
Use method: addTranslation for extending translations list.
Use translationMiddleware instead of translation.
API
TranslationMiddlewareService
| Method | Description | Default | Values |
|---|---|---|---|
| translations | Getter for displaying all loaded and added translations | {} | -- |
| language | Getter for displaying selected language. | 'en' | 'en','nl','it','fr','es','de' |
| setTranslations | Replace all loaded translations. Custom translations will stay unchanged | -- | - |
| extendTranslations | Extend loaded translations by another load | -- | -- |
| addTranslation | Add custom translation. If key will be same as loaded, this translations will be major. | -- | -- |
| setLanguage | Switch language. It will trigger listenLanguage$ | -- | -- |
| listenLanguage$ | Observable value for getting language updates | -- | -- |
| translate | Get current language translation by key and with params if required. | -- | -- |
Troubleshooting
If you have no i18n folder in your assets or en.json file you will start getting 404 error in your console. Ignore it or add i18n/en.json as default file.