compare_arb 1.0.1
compare_arb: ^1.0.1 copied to clipboard
compare_arb 是一个用于处理多语言 JSON 文件的工具
compare_arb 使用说明 #
compare_arb 是一个用于处理多语言 JSON 文件的工具。它能够根据输入文件 input.json 和 多语言源文件 生成对应的输出文件 output_*.json,方便管理和更新多语言内容。
使用步骤 #
1. 添加依赖
在终端中运行以下命令激活 compare_arb:
flutter pub global activate compare_arb
确保依赖安装成功后,即可全局使用该工具。
2. 准备文件
进入目标文件夹,确保文件夹中包含以下文件:
input.json: 表示需要生成的多语言数据。- 多语言源文件(如
source_*.json): 表示各语言的多语言源数据文件(如source_en.json、source_zh.json等)。
示例文件结构:
folder/
├── input.json
├── source_en.json
├── source_zh.json
├── source_de.json
-
input.json示例:{ "date": "枣", "elderberry": "接骨木果", "fig": "无花果" } -
source_en.json示例:{ "apple": "Apple", "banana": "Banana", "cherry": "Cherry", "date": "Date", "elderberry": "Elderberry", "fig": "Fig", "grape": "Grape", "honeydew": "Honeydew", "jackfruit": "Jackfruit", "kiwi": "Kiwi", "lemon": "Lemon" } -
source_zh.json示例:{ "apple": "苹果", "banana": "香蕉", "cherry": "樱桃", "date": "枣", "elderberry": "接骨木果", "fig": "无花果", "grape": "葡萄", "honeydew": "哈密瓜", "jackfruit": "木菠萝", "kiwi": "猕猴桃", "lemon": "柠檬" }
3. 运行指令
在终端中导航到包含上述文件的文件夹,并运行以下命令:
flutter pub global run compare_arb
工具会自动读取 input.json 和所有非 output_ 开始的文件,按照 input.json 中的键值结构生成对应的 output_*.json 文件。
4. 查看生成文件
执行完成后,工具将在同一目录下生成 output_*.json 文件。例如:
-
output_en.json:{ "date": "Date", "elderberry": "Elderberry", "fig": "Fig" } -
output_zh.json:{ "date": "枣", "elderberry": "接骨木果", "fig": "无花果" }
这些生成的文件即可用于多语言处理。
注意事项 #
-
文件内容必须是合法 JSON 格式。
- 所有的
input和 多语言源文件 应为 JSON 格式且符合 JSON 规范。
- 所有的
-
文件命名要求:
input.json: 必须以input开头。
-
处理结果:
- 如果某个键在
input.json中存在,但在对应的 多语言源文件 中缺失,生成的output_*.json会将其值设为null。
- 如果某个键在
-
更新生成:
- 每次运行指令都会重新生成
output_*.json文件,确保数据是最新的。
- 每次运行指令都会重新生成
通过 compare_arb,您可以轻松管理多语言内容的更新和生成。