ngx-translate:从Angular 6库加载JSON

问题描述 投票:2回答:1

我正在使用3个库构建Angular 6应用程序...

我想有3个json文件,每个文件都包含翻译。

是否可以让TranslateLoader从已安装的库中读取这些文件。所以我可以这样说

new TranslateLibraryLoader(http, ["@company/lib1", "@company/lib2", 
"@company/lib3", "./assets/i18n/"]
angular ngx-translate
1个回答
2
投票

ngx-translate在运行时需要库中的文件。首先,您必须告诉angular将这些文件集成到您的构建中。在你的angular.json做:

"assets": [
  {
    "input": "./path-to-company/lib1/translations.json",
    "bundleName": "translations.lib1.json",
    "lazy": true
  },
  // repeat for all libs
],

然后你可以配置一个TranslateHttpLoader来加载这些文件或implement your own one

export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, yourPath, yourSuffix);
}
© www.soinside.com 2019 - 2024. All rights reserved.