在Angular项目中,可以使用ngx-translate库来实现国际化(i18n)。要并行运行Angular i18n构建,可以使用以下步骤:
angular.json
文件中,找到projects
-> your-project-name
-> architect
-> build
-> options
,添加localize
属性并设置为false
。这将禁用默认的i18n构建。"projects": {
"your-project-name": {
"architect": {
"build": {
"options": {
"localize": false
}
}
}
}
}
package.json
文件中,找到scripts
,添加一个新的脚本命令用于并行运行i18n构建。"scripts": {
"i18n": "ng extract-i18n && ng build --localize"
}
npm run i18n
这将首先运行ng extract-i18n
命令来提取项目中的翻译字符串,并将它们保存到src/locale
目录下的各个语言文件中。然后,它将运行ng build --localize
命令来并行构建项目的所有语言版本。
请注意,要使用ngx-translate库来实现国际化,您需要在项目中安装和配置该库。您可以通过以下命令来安装ngx-translate:
npm install @ngx-translate/core @ngx-translate/http-loader --save
然后,在您的Angular模块中导入ngx-translate模块,并配置它。
import { NgModule } from '@angular/core';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http);
}
@NgModule({
imports: [
// ...
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
})
// ...
]
})
export class YourModule { }
这样,您就可以在项目中使用ngx-translate来实现国际化了。
上一篇:并行运行 AWS Glue 作业