Angular2和Webpack-i18n插件vs ng2-translate [英] Angular2 and webpack - i18n plugin vs ng2-translate

查看:63
本文介绍了Angular2和Webpack-i18n插件vs ng2-translate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用angular2构建一个Web应用程序,并将其与webpack捆绑在一起. 提供多种语言的最佳方法是什么?

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/webpack/i18n-webpack-plugin

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

ng2-translate: https://github.com/ocombe/ng2-translate

ng2-translate: https://github.com/ocombe/ng2-translate

推荐答案

我使用菜谱将其与webpack一起使用. xliff文件必须像这样转换为ts:

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

export const TRANSLATION_SV = `<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="en" datatype="plaintext" original="ng2.template">
    <body>
    <trans-unit id="a73e2898b9e1126ed19dbabe4b5c3715a84db61a" datatype="html">
      <source>Category</source>
      <target>Kategori</target>
    </trans-unit>
    </body>
  </file>
</xliff>`;

然后在main.ts中必须添加

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';

并插入到引导步骤:

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

这篇关于Angular2和Webpack-i18n插件vs ng2-translate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆