Angular2 and webpack - i18n plugin vs ng2-translate

后端 未结 5 1796
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  感情败类
    2020-12-24 04:29

    If you are using angular-cli you can follow these steps:

    Be aware that your app must be AOT compatibe, so you should be able to build it with --aot switch:

    ng build --aot
    
    1. Extract messages with ng xi18n command with location for translation file given:

      ng xi18n --output-path src/i18n
      
    2. You will get src/i18n/messages.xlf file. Copy this file and translate messages to languages you need:

      src/i18n/messages.en.xlf
      src/i18n/messages.pl.xlf
      
    3. Serve/build your app with ng serve / ng build command (change locale accordingly):

      ng serve --i18n-file=src/i18n/messages.en.xlf --locale=en --i18n-format=xlf --aot
      

提交回复
热议问题