Remove Localisation templates

This commit is contained in:
simibubi 2023-01-24 14:12:04 +01:00
parent 94be8b33b0
commit 6606a07d44
20 changed files with 4 additions and 54678 deletions

View file

@ -560,24 +560,6 @@ bf2b0310500213ff853c748c236eb5d01f61658e assets/create/blockstates/yellow_toolbo
b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json b7181bcd8182b2f17088e5aa881f374c9c65470c assets/create/blockstates/zinc_ore.json
f85edc574ee6de0de7693ffb031266643db6724a assets/create/lang/en_ud.json f85edc574ee6de0de7693ffb031266643db6724a assets/create/lang/en_ud.json
c219c77242e645f32704201dd80e279b3759b794 assets/create/lang/en_us.json c219c77242e645f32704201dd80e279b3759b794 assets/create/lang/en_us.json
ed60920301f2ffcffeea71f37e24545e72ee0a31 assets/create/lang/unfinished/da_dk.json
2724878ebb8921a094f489491c438cf8b36a30a2 assets/create/lang/unfinished/de_de.json
fa5cb1ce51545f01712936755294760f51703284 assets/create/lang/unfinished/es_cl.json
f6c96d50d7698428ae1e1b9f076ff864f399b7b5 assets/create/lang/unfinished/es_es.json
093e082838d64597386ff285bc9554825f066a39 assets/create/lang/unfinished/es_mx.json
8e73758eb200cde4f670d1c144dfc404acd2b8d0 assets/create/lang/unfinished/fr_fr.json
55d6af7afea4b03a2b7052e05a1bef61e89218e5 assets/create/lang/unfinished/it_it.json
d13c11d10974365d8facdb16f82ee96eb4dcc0d7 assets/create/lang/unfinished/ja_jp.json
21d5bc06ee7c0f12a2b0dfab5a871f6255839c44 assets/create/lang/unfinished/ko_kr.json
f0a39b64b067225a6b2f8508c99042be160c5cfe assets/create/lang/unfinished/nl_nl.json
31e1c8ae5377a70311d225aa7e31d6810bc6a231 assets/create/lang/unfinished/pl_pl.json
24a2408e187eb1cd15912cded83f65a0c050f26c assets/create/lang/unfinished/pt_br.json
0dec1ecc63fae7aeb82abe9810e48706761201ed assets/create/lang/unfinished/pt_pt.json
f619a46a75eb83175d2beb7cdde4eb6e02429a3d assets/create/lang/unfinished/ro_ro.json
738828862cdec76293de65147b1dd628156556d6 assets/create/lang/unfinished/ru_ru.json
bc2c343371bed774bd817ef12e295f6aa2363654 assets/create/lang/unfinished/uk_ua.json
79b2bd96514e4e472ef8da844ed824027765c07c assets/create/lang/unfinished/zh_cn.json
a1d73503bd0f9052d53c668dc9e7a4ccfa4058f6 assets/create/lang/unfinished/zh_tw.json
487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json 487a511a01b2a4531fb672f917922312db78f958 assets/create/models/block/acacia_window.json
b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json b48060cba1a382f373a05bf0039054053eccf076 assets/create/models/block/acacia_window_pane_noside.json
3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json 3066db1bf03cffa1a9c7fbacf47ae586632f4eb3 assets/create/models/block/acacia_window_pane_noside_alt.json

View file

@ -3,28 +3,19 @@ package com.simibubi.create.foundation.data;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects; import java.util.Objects;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
import org.apache.commons.lang3.tuple.Pair;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderScene;
import com.simibubi.create.foundation.utility.FilesHelper;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraft.data.DataProvider; import net.minecraft.data.DataProvider;
@ -44,10 +35,6 @@ public class LangMerger implements DataProvider {
private final LangPartial[] langPartials; private final LangPartial[] langPartials;
private List<Object> mergedLangData; private List<Object> mergedLangData;
private Map<String, List<Object>> populatedLangData;
private Map<String, Map<String, String>> allLocalizedEntries;
private Map<String, MutableInt> missingTranslationTally;
private List<String> langIgnore; private List<String> langIgnore;
public <T extends LangPartial> LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) { public <T extends LangPartial> LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) {
@ -57,9 +44,6 @@ public class LangMerger implements DataProvider {
this.langPartials = langPartials; this.langPartials = langPartials;
this.mergedLangData = new ArrayList<>(); this.mergedLangData = new ArrayList<>();
this.langIgnore = new ArrayList<>(); this.langIgnore = new ArrayList<>();
this.allLocalizedEntries = new HashMap<>();
this.populatedLangData = new HashMap<>();
this.missingTranslationTally = new HashMap<>();
populateLangIgnore(); populateLangIgnore();
} }
@ -86,42 +70,11 @@ public class LangMerger implements DataProvider {
Path path = this.gen.getOutputFolder() Path path = this.gen.getOutputFolder()
.resolve("assets/" + modid + "/lang/" + "en_us.json"); .resolve("assets/" + modid + "/lang/" + "en_us.json");
for (Pair<String, JsonElement> pair : getAllLocalizationFiles()) {
if (!pair.getRight()
.isJsonObject())
continue;
Map<String, String> localizedEntries = new HashMap<>();
JsonObject jsonobject = pair.getRight()
.getAsJsonObject();
jsonobject.entrySet()
.stream()
.forEachOrdered(entry -> {
String key = entry.getKey();
if (key.startsWith("_"))
return;
String value = entry.getValue()
.getAsString();
localizedEntries.put(key, value);
});
String key = pair.getKey();
allLocalizedEntries.put(key, localizedEntries);
populatedLangData.put(key, new ArrayList<>());
missingTranslationTally.put(key, new MutableInt(0));
}
collectExistingEntries(path); collectExistingEntries(path);
collectEntries(); collectEntries();
if (mergedLangData.isEmpty()) if (mergedLangData.isEmpty())
return; return;
save(cache, mergedLangData, path, "Merging en_us.json with hand-written lang entries...");
save(cache, mergedLangData, -1, path, "Merging en_us.json with hand-written lang entries...");
for (Entry<String, List<Object>> localization : populatedLangData.entrySet()) {
String key = localization.getKey();
Path populatedLangPath = this.gen.getOutputFolder()
.resolve("assets/" + modid + "/lang/unfinished/" + key);
save(cache, localization.getValue(), missingTranslationTally.get(key)
.intValue(), populatedLangPath, "Populating " + key + " with missing entries...");
}
} }
private void collectExistingEntries(Path path) throws IOException { private void collectExistingEntries(Path path) throws IOException {
@ -167,19 +120,10 @@ public class LangMerger implements DataProvider {
private void writeData(String data) { private void writeData(String data) {
mergedLangData.add(data); mergedLangData.add(data);
populatedLangData.values()
.forEach(l -> l.add(data));
} }
private void writeEntry(String key, String value) { private void writeEntry(String key, String value) {
mergedLangData.add(new LangEntry(key, value)); mergedLangData.add(new LangEntry(key, value));
populatedLangData.forEach((k, l) -> {
ForeignLangEntry entry = new ForeignLangEntry(key, value, allLocalizedEntries.get(k));
if (entry.isMissing())
missingTranslationTally.get(k)
.increment();
l.add(entry);
});
} }
protected boolean shouldAddLineBreak(String key, String previousKey) { protected boolean shouldAddLineBreak(String key, String previousKey) {
@ -201,40 +145,15 @@ public class LangMerger implements DataProvider {
return !split[0].equals(split2[0]); return !split[0].equals(split2[0]);
} }
private List<Pair<String, JsonElement>> getAllLocalizationFiles() {
ArrayList<Pair<String, JsonElement>> list = new ArrayList<>();
String filepath = "assets/" + modid + "/lang/";
try (InputStream resourceStream = ClassLoader.getSystemResourceAsStream(filepath)) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceStream));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null)
break;
if (!readLine.endsWith(".json"))
continue;
if (readLine.startsWith("en_us") || readLine.startsWith("en_ud"))
continue;
list.add(Pair.of(readLine, FilesHelper.loadJsonResource(filepath + readLine)));
}
} catch (IOException | NullPointerException e) {
e.printStackTrace();
}
return list;
}
private void collectEntries() { private void collectEntries() {
for (LangPartial partial : langPartials) for (LangPartial partial : langPartials)
addAll(partial.getDisplayName(), partial.provide() addAll(partial.getDisplayName(), partial.provide()
.getAsJsonObject()); .getAsJsonObject());
} }
private void save(HashCache cache, List<Object> dataIn, int missingKeys, Path target, String message) private void save(HashCache cache, List<Object> dataIn, Path target, String message)
throws IOException { throws IOException {
String data = createString(dataIn, missingKeys); String data = createString(dataIn);
// data = JavaUnicodeEscaper.outsideOf(0, 0x7f)
// .translate(data);
String hash = DataProvider.SHA1.hashUnencodedChars(data) String hash = DataProvider.SHA1.hashUnencodedChars(data)
.toString(); .toString();
if (!Objects.equals(cache.getHash(target), hash) || !Files.exists(target)) { if (!Objects.equals(cache.getHash(target), hash) || !Files.exists(target)) {
@ -249,11 +168,9 @@ public class LangMerger implements DataProvider {
cache.putNew(target, hash); cache.putNew(target, hash);
} }
protected String createString(List<Object> data, int missingKeys) { protected String createString(List<Object> data) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("{\n"); builder.append("{\n");
if (missingKeys != -1)
builder.append("\t\"_\": \"Missing Localizations: " + missingKeys + "\",\n");
data.forEach(builder::append); data.forEach(builder::append);
builder.append("\t\"_\": \"Thank you for translating ").append(displayName).append("!\"\n\n"); builder.append("\t\"_\": \"Thank you for translating ").append(displayName).append("!\"\n\n");
builder.append("}"); builder.append("}");
@ -278,19 +195,4 @@ public class LangMerger implements DataProvider {
} }
private class ForeignLangEntry extends LangEntry {
private boolean missing;
ForeignLangEntry(String key, String value, Map<String, String> localizationMap) {
super(key, localizationMap.getOrDefault(key, "UNLOCALIZED: " + value));
missing = !localizationMap.containsKey(key);
}
public boolean isMissing() {
return missing;
}
}
} }