Angular - 使用外部翻译 'assets'
Angular - Use translation from outside 'assets'
我需要将我的翻译文件添加到 assets
目录之外,如下所示:
src/app/custom/i18n/en.json
我正在加载这样的翻译:
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './app/custom/i18n/', '.json');
}
但这不起作用,因为它找不到文件:
GET http://localhost:8100/app/custom/i18n/en.json 404 (Not Found)
我尝试自定义 angular.json
文件以便能够访问 'assets' 之外的文件,这样做是这样的:
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "src/app/common",
"output": "assets"
}
]
但我仍然收到 404 错误。请告知如何将翻译设置为使用 assets
外部的 json 文件。谢谢!
您需要在资产数组中指定消息文件。由于 custom/i18n/en.json 未在资产数组中指定,因此在构建项目时不会将其捆绑。因此给出 404 错误
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "src/app/common",
"output": "assets"
},
"custom/i18n/en.json"
]
我需要将我的翻译文件添加到 assets
目录之外,如下所示:
src/app/custom/i18n/en.json
我正在加载这样的翻译:
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './app/custom/i18n/', '.json');
}
但这不起作用,因为它找不到文件:
GET http://localhost:8100/app/custom/i18n/en.json 404 (Not Found)
我尝试自定义 angular.json
文件以便能够访问 'assets' 之外的文件,这样做是这样的:
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "src/app/common",
"output": "assets"
}
]
但我仍然收到 404 错误。请告知如何将翻译设置为使用 assets
外部的 json 文件。谢谢!
您需要在资产数组中指定消息文件。由于 custom/i18n/en.json 未在资产数组中指定,因此在构建项目时不会将其捆绑。因此给出 404 错误
"assets": [
{
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "src/app/common",
"output": "assets"
},
"custom/i18n/en.json"
]