Rab*_*adi 5 locale internationalization angular angular8
我用法语构建了一个 angular 应用程序,所以现在我想使用国际化 (i18n) 以其他语言(如 En)提供它,所以问题是 Angular 的默认语言环境是 En-es,当我写这个时<span i18n>Mes endroits</span>,我有这个
<file source-language= "en-US" datatype="plaintext" original="ng2.template">// source is English
<body>
<trans-unit id="4df6e2173dc9d9f8c60481273cf3371981e60fde" datatype="html">
<source>Mes endroits</source> ... // but this is in french
Run Code Online (Sandbox Code Playgroud)
我希望源语言为fr并提供例如messages.en.xlf
所以我可以将默认语言环境更改为 fr ,或者我必须用英语重写我的代码并提供 messages.fr.xlf
这应该可以通过sourceLocale在angular.json文件中设置。在我的例子中,核心应用程序是德语,所以文件的相关部分如下:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-client": {
"i18n": {
"sourceLocale": {
"code": "de",
"baseHref": ""
},
"locales": {
"en": {
"translation": "src/locale/messages.en.xlf",
"baseHref": ""
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
对我来说,这正如预期的那样工作,XLF 文件的属性都正确。
小智 2
这可以帮助您ngx-translate/ng2-translate,这个库在角度项目中非常常见。
我个人更喜欢用这种方式进行翻译。
您将能够使用翻译管道。像这样
<p>{{ 'myPlaces' | translate }}</p>
Run Code Online (Sandbox Code Playgroud)
在 fr.json 中定义:
{ 'myPlaces' : 'Mes endroits' }
Run Code Online (Sandbox Code Playgroud)
我让你检查文档
| 归档时间: |
|
| 查看次数: |
4311 次 |
| 最近记录: |