【发布时间】:2020-01-20 16:32:45
【问题描述】:
我们有两个独立的代码库,它们使用不同的本地化风格。其中一个代码库使用 yaml,另一个使用 JSON。
现在,我们正在慢慢迁移到使用 JSON 的代码库,但是使用 20k yaml 字符串和 7 种不同的语言,手动转换这一切是一件很痛苦的事情。不幸的是,我们在 yaml 文件中使用的是字符串表示法而不是对象表示法,因此像 this 这样的转换器将无法工作。
示例 yaml
cart.title.primary: Cart
cart.title.secondary: Buy products
cart.dialog.title: Remove product
cart.dialog.text: Are you sure to remove this product?
变成转换器这个
{
"cart.title.primary": "Cart",
"cart.title.secondary": "Buy products",
"cart.dialog.title": "Remove product",
"cart.dialog.text": "Are you sure to remove this product?"
}
但我想要的是字符串中的每个点实际上是 JSON 中的一个对象。所以理想情况下,我提供的 yaml 应该是这样的:
{
"cart": {
"title": {
"primary": "Cart",
"secondary: "Buy Products"
},
"dialog": {
"title": "Remove product",
"text": "Are you sure to remove this product?"
}
}
}
有没有做过类似事情的人?首选。使用 PHP 或 JavaScript。提前致谢!
【问题讨论】:
标签: javascript php json yaml