mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-23 08:30:21 +08:00
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.
This commit is contained in:
47
scripts/convert_arb_keys.dart
Executable file
47
scripts/convert_arb_keys.dart
Executable file
@ -0,0 +1,47 @@
|
||||
#!/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;
|
||||
}
|
Reference in New Issue
Block a user