本地化 Angular 11 库

问题描述

Angular i18n docs 清楚地说明了本地化应用程序,但并未提及图书馆。

ng add @angular/localize修改 angular.jsonng extract-i18n 失败并出现以下错误

angular.json

中缺少提取 i18n

An unhandled exception occurred: No projects support the 'extract-i18n' target.

extract-i18n添加 angular.json 目标

Data path "" should have required property 'browserTarget'.

如何为我的库生成 messages.xlf 文件

解决方法

截至 2021 年 3 月,这是 not yet supported

但是有 a workaround

首先像安装普通应用一样安装 @angular/localize :

ng add @angular/localize

package.json 中,添加以下脚本以扫描构建文件中的本地化字符串

"i18n": "localize-extract -r . -s \"dist/efp-widgets/fesm2015/*.js\" -f xlf -o messages.xlf"

注意 localize-extract 来自 @angular/localize;

如果在 TypeScript 中使用 $localize,不要忘记在 @angular/localize/init 中注册 public-api.ts :

import '@angular/localize/init'

然后将 i18n 脚本添加到 package.json 中的主构建脚本:

"build": "ng build && npm run i18n"

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...