Angular 翻译不适用于 angular 9
Angular translation not working with angular 9
我有一个 Angular9 应用程序。除了app.module.ts,还有一个模块,custom.module.ts。这是
package.json
"@angular/cdk": "^9.2.4",
"@angular/common": "9.1.11",
"@angular/compiler": "9.1.11",
"@angular/core": "9.1.11",
待翻译
1) 我添加了 @ngx-translate/core
和 @ngx-translate/http-loader
"@ngx-translate/core": "10.0.2",
"@ngx-translate/http-loader": "^5.0.0",
2)然后在app.module.ts下imports
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
和
// required for AOT compilation
export function HttpLoaderFactory(http: HttpClient): any {
return new TranslateHttpLoader(http, "./assets/i18n/");
}
我为我的 custom.module.ts.
做了同样的事情
3) app.component.ts
// Add languages
this.translateService.addLangs(["en", "nb", "sv"]);
// Use a language
this.translateService.setDefaultLang("en");
this.translateService.use("en");
4) 个文件在 assets/i18n/en.json
{
"noSelectMessage": "Select to see detail."
}
现在我在 custom.moule.ts
的组件中使用 traslate 管道
<span>{{'noSelectMessage' | translate}}</span>
显示相同 noSelectMessage
并且如果我在浏览器中检查源选项卡,资产下没有 i18n 文件夹。
可能是什么问题?
我在 custom.module.ts 的一个组件和 custom.module.ts 文件中使用翻译服务做
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
我需要做的就是导入 TranslateModule
,以支持翻译管道。
我有一个 Angular9 应用程序。除了app.module.ts,还有一个模块,custom.module.ts。这是
package.json
"@angular/cdk": "^9.2.4",
"@angular/common": "9.1.11",
"@angular/compiler": "9.1.11",
"@angular/core": "9.1.11",
待翻译
1) 我添加了 @ngx-translate/core
和 @ngx-translate/http-loader
"@ngx-translate/core": "10.0.2",
"@ngx-translate/http-loader": "^5.0.0",
2)然后在app.module.ts下imports
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
和
// required for AOT compilation
export function HttpLoaderFactory(http: HttpClient): any {
return new TranslateHttpLoader(http, "./assets/i18n/");
}
我为我的 custom.module.ts.
做了同样的事情3) app.component.ts
// Add languages
this.translateService.addLangs(["en", "nb", "sv"]);
// Use a language
this.translateService.setDefaultLang("en");
this.translateService.use("en");
4) 个文件在 assets/i18n/en.json
{
"noSelectMessage": "Select to see detail."
}
现在我在 custom.moule.ts
的组件中使用 traslate 管道<span>{{'noSelectMessage' | translate}}</span>
显示相同 noSelectMessage
并且如果我在浏览器中检查源选项卡,资产下没有 i18n 文件夹。
可能是什么问题?
我在 custom.module.ts 的一个组件和 custom.module.ts 文件中使用翻译服务做
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
我需要做的就是导入 TranslateModule
,以支持翻译管道。