TranslationPruner v2
This commit is contained in:
parent
1ff416fc5a
commit
a1ad345f86
@ -53,28 +53,30 @@ public class TranslationPruner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (args.length < 3) {
|
if (args.length < 2) {
|
||||||
System.err.println("Usage: java TranslationPruner <source.json> <reference.json> [output.json]");
|
System.err.println("Usage: `java TranslationPruner <source folder> <dest folder>`, where dest folder must contain the locale.constant-en_US.json for reference structure.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
File sourceFile = new File(args[0]);
|
File sourceFolder = new File(args[0]);
|
||||||
File referenceFile = new File(args[1]);
|
File destFolder = new File(args[1]);
|
||||||
File outputFile = new File(args[2]);
|
|
||||||
|
|
||||||
|
File referenceFile = new File(destFolder, "locale.constant-en_US.json");
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode usRoot = mapper.readTree(referenceFile);
|
JsonNode usRoot = mapper.readTree(referenceFile);
|
||||||
Set<String> validKeys = new HashSet<>();
|
Set<String> validKeys = new HashSet<>();
|
||||||
collectKeys(usRoot, "", validKeys);
|
collectKeys(usRoot, "", validKeys);
|
||||||
|
for (File sourceFile : sourceFolder.listFiles()) {
|
||||||
|
File destFile = new File(destFolder, sourceFile.getName());
|
||||||
|
JsonNode sourceRoot = mapper.readTree(sourceFile);
|
||||||
|
if (!sourceRoot.isObject()) {
|
||||||
|
throw new IllegalArgumentException("Source JSON must be an object at root");
|
||||||
|
}
|
||||||
|
ObjectNode pruned = pruneNode((ObjectNode) sourceRoot, validKeys, "", mapper);
|
||||||
|
|
||||||
JsonNode sourceRoot = mapper.readTree(sourceFile);
|
mapper.writerWithDefaultPrettyPrinter().writeValue(destFile, pruned);
|
||||||
if (!sourceRoot.isObject()) {
|
System.out.println("Pruned translation written to " + destFile.getPath());
|
||||||
throw new IllegalArgumentException("Source JSON must be an object at root");
|
|
||||||
}
|
}
|
||||||
ObjectNode pruned = pruneNode((ObjectNode) sourceRoot, validKeys, "", mapper);
|
|
||||||
|
|
||||||
mapper.writerWithDefaultPrettyPrinter().writeValue(outputFile, pruned);
|
|
||||||
System.out.println("Pruned translation written to " + outputFile.getPath());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(2);
|
System.exit(2);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user