Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The documentation says that you need this code in your app.module.ts to load language files dynamically:
- {
- provide: TRANSLATIONS,
- useFactory: (locale) => {
- locale = locale || 'en'; // default to english if no locale provided
- return require(`raw-loader!../locale/messages.${locale}.xlf`);
- },
- deps: [LOCALE_ID]
- }
- But you have to keep in mind that this will fail if you try to load your default language file.
- For example we write our App in German and then generate with ng xi18n a translation.de.xlf file. This default file does
- correctly only have a source language and no target language. But without them i18n-polyfill will crash. So you have to
- extend the code:
- {
- provide: TRANSLATIONS,
- useFactory: (locale) => {
- locale = locale || 'en';
- if (locale === 'de') { // de is our default
- return '';
- } else {
- return require(`raw-loader!../../i18n/translation.${locale}.xlf`);
- }
- },
- deps: [LOCALE_ID]
- }
- Here you return nothing but an empty string if your app runs with the default language.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement