json - 可以将变量传递给 angular.json 并避免代码重复吗?
问题描述
我正在寻找一种将信息传递到angular.json
文件的方法,这样我就不需要重复构建配置并避免所有代码重复。我不能很好地解释,所以我会尝试一个例子。所以在我的angular.json
下面configurations
我有类似的东西
"configurations": {
"de": {
"aot": true,
"i18nLocale": "de",
"i18nFile": "project/src/locale/messages.de.xlf",
"i18nFormat": "xlf"
},
"en-gb": {
"aot": true,
"i18nLocale": "en-gb",
"i18nFile": "project/src/locale/messages.en-gb.xlf",
"i18nFormat": "xlf"
},
"en-us": {
"aot": true,
"i18nLocale": "en-us",
"i18nFile": "project/src/locale/messages.en-us.xlf",
"i18nFormat": "xlf"
},
"es": {
"aot": true,
"i18nLocale": "es",
"i18nFile": "project/src/locale/messages.es.xlf",
"i18nFormat": "xlf"
},
"fr": {
"aot": true,
"i18nLocale": "fr",
"i18nFile": "project/src/locale/messages.fr.xlf",
"i18nFormat": "xlf"
},
"it": {
"aot": true,
"i18nLocale": "it",
"i18nFile": "project/src/locale/messages.it.xlf",
"i18nFormat": "xlf"
},
"pt-br": {
"aot": true,
"i18nLocale": "pt-br",
"i18nFile": "project/src/locale/messages.pt-br.xlf",
"i18nFormat": "xlf"
}
有没有办法让我们说一个变量i18n
,我可以angular.json
像这样使用它$i18n
:
"configurations": {
"i18n": {
"aot": true,
"i18nLocale": "$i18n",
"i18nFile": "project/src/locale/messages.$i18n.xlf",
"i18nFormat": "xlf"
}
我英语不好。我希望我用这个例子很好地解释了我正在寻找的东西。提前致谢。
解决方案
我不会说angular,但希望这很有用,我想你正在看这样的东西:
echo '["de","en-gb","en-us","es","fr","it"]' | jq '
{"configuration":[ .[] as $c |
{
($c):{
"aot":true,
"i18nLocale": $c,
"i18nFile": ("project/src/locale/messages." + $c + ".xlf"),
"i18nFormat": "xlf"
}
}
]}'
根据您的第一个示例,此命令使用jq 命令行解析器来伪造 JSON 配置。
您可以将发送echo
到的表扩展jq
为任何国家/地区字符串并获得尽可能多的配置。
推荐阅读
- java - 如何保存从图库中挑选的图像?
- python - 将元组从列表附加到另一个并打印的问题
- android - 更新到 AS 3.3 后“PKIX 路径构建失败”
- fonts - “不存在支持的字形形状表”[OpenType 字体]
- php - 如何在本地网络上共享一个 laravel 项目
- c# - 如何使用 C# 将数据从网站检索到我的 winforms
- c# - 如何挂钩事件或 WPF 应用程序中窗口的更改?
- linux - centos7我设置了这个脚本开机,重启后服务没有启动
- angular-reactive-forms - 如何将 formControlName 绑定到静态单选按钮值
- ios - iOS BLE 后台执行时间