初始化
This commit is contained in:
42
tool/gen_arb.dart
Normal file
42
tool/gen_arb.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import "package:yaml/yaml.dart";
|
||||
|
||||
void main() {
|
||||
//输如文件,和输出目录
|
||||
var inputFile = File("lib/l10n/arb/i18n.yaml");
|
||||
var outDir = Directory("lib/l10n/arb");
|
||||
|
||||
if (!inputFile.existsSync()) {
|
||||
print('❌ i18n.yaml 文件不存在:$inputFile');
|
||||
exit(1);
|
||||
}
|
||||
//获取数据,转为map
|
||||
final yamlMap = loadYaml(inputFile.readAsStringSync());
|
||||
|
||||
Map<String, Map<String, dynamic>> arbMaps = {};
|
||||
|
||||
yamlMap.forEach((key, mapValue) {
|
||||
final description = mapValue['description'] ?? '';
|
||||
//循环语言
|
||||
mapValue.forEach((lang, text) {
|
||||
//跳过description
|
||||
if (lang == 'description') return;
|
||||
|
||||
if (!arbMaps.containsKey(lang)) {
|
||||
arbMaps[lang] = {};
|
||||
}
|
||||
arbMaps[lang]?[key] = text;
|
||||
if (description != "") {
|
||||
arbMaps[lang]?['@$key'] = {'description': description};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//创建文件
|
||||
arbMaps.forEach((lang,json){
|
||||
final file = File("${outDir.path}/app_$lang.arb");
|
||||
final encoder = JsonEncoder.withIndent(' ');
|
||||
file.writeAsStringSync(encoder.convert(json));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user