Angular2 and webpack - i18n plugin vs ng2-translate

后端 未结 5 1804
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 04:01

I want to build a web-application with angular2 and bundle this with webpack. What is the best way for providing multiple languages:

i18n-plugin: https://github.com/

5条回答
  •  猫巷女王i
    2020-12-24 04:36

    I got it working with webpack using the cookbook. The xliff file has to be converted to ts like so:

    export const TRANSLATION_SV = `
    
      
        
        
          Category
          Kategori
        
        
      
    `;

    Then in the main.ts it has to be added

    import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID  } from '@angular/core';
    import { TRANSLATION_SV } from './locale/messages.sv';
    

    and inserted to the bootstrap step:

    platformBrowserDynamic().bootstrapModule(AppModule, {
        providers: [
          {provide: TRANSLATIONS, useValue: TRANSLATION_SV},
          {provide: TRANSLATIONS_FORMAT, useValue: "xlf"},
          {provide: LOCALE_ID, useValue:'sv'}
        ];
    });
    

提交回复
热议问题