Files
GitJournal/scripts/convert_arb_keys.dart
Vishesh Handa b56ae4c882 Convert the json localization file to arb
Also added a script to combine all the keys. The arb which we get from
poeditor have multiple objects.
2022-11-19 02:03:11 +01:00

48 lines
1019 B
Dart
Executable File

#!/usr/bin/env dart
// SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <me@vhanda.in>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
// ignore_for_file: avoid_print
import 'dart:async';
import 'dart:convert';
import 'dart:io';
Future<int> main(List<String> args) async {
var contents = await File(args[0]).readAsString();
var ds = json.decode(contents);
process([], ds);
print(json.encode(newMap));
return 0;
}
Map<String, String> newMap = {};
void process(List<String> prefixes, Map<String, dynamic> map) {
for (var entry in map.entries) {
var p = [...prefixes, entry.key];
if (entry.value is String) {
newMap[toCamel(p)] = entry.value;
continue;
}
assert(entry.value is Map);
process(p, entry.value);
}
}
String toCamel(List<String> l) {
var str = l[0].toLowerCase();
for (var i = 1; i < l.length; i++) {
var s = l[i].toLowerCase();
s = s.replaceRange(0, 1, s[0].toUpperCase());
// ignore: use_string_buffers
str += s;
}
return str;
}