简体   繁体   English

在 Angular 4 中使用 AOT 的 i18n

[英]i18n using AOT in Angular 4

We have a requirement and asked to use Angular 4 and I am working on implementing internationalization.我们有一个要求并要求使用 Angular 4,我正在努力实现国际化。 Since I am new to angular I was going through i18n and found that i18n with AOT currently supports only the translation in template.由于我是 angular 的新手,我正在浏览 i18n 并发现带有 AOT 的 i18n 目前仅支持模板中的翻译。 What does it mean when they say the support is only in the template, can anybody explain with some example.当他们说支持仅在模板中时是什么意思,任何人都可以用一些例子来解释。

Are there any good examples to implement i18n and also to render based on browser locale.是否有任何很好的示例来实现 i18n 以及基于浏览器区域设置进行渲染。

It means that you cannot translate text from within your TypeScript code;这意味着您无法从 TypeScript 代码中翻译文本; only static HTML content can be translated.只能翻译静态 HTML 内容。

Can be translated可以翻译

<p i18n>Text in a paragraph</p>
        ^^^^^^^^^^^^^^^^^^
<my-component title="My Title" i18n-title></my-component>
                     ^^^^^^^

Cannot be translated无法翻译

if (hasError) {
  showErrorMessage('An error has occured');
                   ^^^^^^^^^^^^^^^^^^^^^^
}

If you want to translate message from within your code, you have to either implement some kind of I18nService yourself, or use one of the alternative libraries like ngx-translate如果你想从你的代码中翻译消息,你必须自己实现某种I18nService ,或者使用像ngx-translate这样的替代库之一

For more in-depth information, just stick to the official docs .如需更深入的信息,请参阅官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM