[英]Http failure during parsing for json file Angular 5 ngx-translate
I want to use ngx translate module but suddenly it started giving this error:我想使用 ngx translate 模块,但突然它开始出现此错误:
Http failure during parsing for http://localhost:8100/assets/i18n/en.json解析http://localhost:8100/assets/i18n/en.json 时Http 失败
I dont know why.我不知道为什么。 All the libraries are included and the function was working normally for 1-2 lines, but when i added more data in json files (en.json and ru.json) it gives this error when I press for translate and of course it does not translate.
包含所有库并且该函数正常工作 1-2 行,但是当我在 json 文件(en.json 和 ru.json)中添加更多数据时,当我按下翻译时会出现此错误,当然它不会翻译。
ru.json ru.json
{
"User Settings": "Настройки юзера",
"Language": "Язык",
"Englsh": "Английский",
}
en.json en.json
{
"User Settings": "User Settings",
"Language": "Language",
"Englsh": "Englsh",
}
page.ts页面.ts
{
translate.setDefaultLang("en");
//code
this.translate.use(lang);
}
Error Http: failure during parsing for http:// localhost:8100/assets/i18n/en.json错误Http: 解析 http://localhost:8100/assets/i18n/en.json 时失败
Use this code for HttpLoaderFactory:将此代码用于 HttpLoaderFactory:
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
and also in your angular.json add i18n folder:并且还在你的 angular.json 添加 i18n 文件夹:
"assets": ["src/assets",
"src/assets/i18n"
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.