mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
Populang
- Outdated localizations will now have a populated counterpart in the generated assets, for easier maintenance
This commit is contained in:
parent
f79d168bc7
commit
a2c19b21d9
13 changed files with 12393 additions and 23 deletions
|
@ -336,7 +336,16 @@ c77b46d8b459e5c7cc495393546f3fcca8a1fa1d assets\create\blockstates\weathered_lim
|
|||
7f39521b211441f5c3e06d60c5978cebe16cacfb assets\create\blockstates\zinc_block.json
|
||||
b7181bcd8182b2f17088e5aa881f374c9c65470c assets\create\blockstates\zinc_ore.json
|
||||
d6d4eaadc6f2c86dd69b8a818ca7352b85be52cd assets\create\lang\en_ud.json
|
||||
0cc26662a5c436a5703926fe3509f0a9536ee737 assets\create\lang\en_us.json
|
||||
56b1f1f0d28a4523ae1e2e57be7d58716edb54bf assets\create\lang\en_us.json
|
||||
eceeb85745ce5b39d3fb0ab594641e7297e3dcee assets\create\lang\unfinished\de_de.json
|
||||
514032f2f67fb4b4eeed311c9c3b7d0e36c31436 assets\create\lang\unfinished\fr_fr.json
|
||||
1b4661d0e99bc26061b53817e5ad8c6a440d4b6a assets\create\lang\unfinished\it_it.json
|
||||
2e7d9659f699f3c3bb4740c354dd4286ee2179cc assets\create\lang\unfinished\ja_jp.json
|
||||
dfa78c83916cbd277ecdfb1783041470556d8399 assets\create\lang\unfinished\ko_kr.json
|
||||
c6df53cb093090c2bfcccf910bb2261d1b0119c2 assets\create\lang\unfinished\nl_nl.json
|
||||
2772dade72823ee9a174638afb5d9cec3834527b assets\create\lang\unfinished\pt_br.json
|
||||
dd03b38344088dfd4517a380e9ed5052b20e4d90 assets\create\lang\unfinished\ru_ru.json
|
||||
ef2f3a2b8c547821203d2f0487e7885bb2d6dcca assets\create\lang\unfinished\zh_cn.json
|
||||
846200eb548d3bfa2e77b41039de159b4b6cfb45 assets\create\models\block\acacia_window.json
|
||||
1930fa3a3c98d53dd19e4ee7f55bc27fd47aa281 assets\create\models\block\acacia_window_pane_noside.json
|
||||
1763ea2c9b981d187f5031ba608f3d5d3be3986a assets\create\models\block\acacia_window_pane_noside_alt.json
|
||||
|
|
|
@ -529,7 +529,7 @@
|
|||
"create.generic.unit.minutes": "Minutes",
|
||||
"create.generic.unit.rpm": "RPM",
|
||||
"create.generic.unit.stress": "su",
|
||||
"create.generic.unit.degrees": "\u00B0",
|
||||
"create.generic.unit.degrees": "°",
|
||||
|
||||
"create.action.scroll": "Scroll",
|
||||
"create.action.confirm": "Confirm",
|
||||
|
@ -1075,7 +1075,7 @@
|
|||
"block.create.furnace_engine.tooltip.behaviour1": "_Starts_ _powering_ a _Flywheel_ placed in front of it (1m apart). Use a Blast Furnace for higher speeds.",
|
||||
|
||||
"block.create.flywheel.tooltip": "FLYWHEEL",
|
||||
"block.create.flywheel.tooltip.summary": "A large metal wheel to _harness_ _and_ _stabilize_ generated force by an _attached_ _Engine_. Flywheels connect to engines if they are _1m_ _apart_ and at a _90\u00B0_ _Angle_ from each other.",
|
||||
"block.create.flywheel.tooltip.summary": "A large metal wheel to _harness_ _and_ _stabilize_ generated force by an _attached_ _Engine_. Flywheels connect to engines if they are _1m_ _apart_ and at a _90°_ _Angle_ from each other.",
|
||||
"block.create.flywheel.tooltip.condition1": "When Attached to Running Engine",
|
||||
"block.create.flywheel.tooltip.behaviour1": "Provides _Rotational_ _Force_ to a connected contraption based on the generator's strength and speed.",
|
||||
|
||||
|
|
1361
src/generated/resources/assets/create/lang/unfinished/de_de.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/de_de.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/fr_fr.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/fr_fr.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/it_it.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/it_it.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/ja_jp.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/ja_jp.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/ko_kr.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/ko_kr.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/nl_nl.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/nl_nl.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/pt_br.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/pt_br.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/ru_ru.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/ru_ru.json
Normal file
File diff suppressed because it is too large
Load diff
1361
src/generated/resources/assets/create/lang/unfinished/zh_cn.json
Normal file
1361
src/generated/resources/assets/create/lang/unfinished/zh_cn.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -3,14 +3,20 @@ package com.simibubi.create.foundation.data;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
import org.apache.commons.lang3.mutable.MutableObject;
|
||||
import org.apache.commons.lang3.text.translate.JavaUnicodeEscaper;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
@ -25,7 +31,6 @@ import net.minecraft.data.DirectoryCache;
|
|||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class LangMerger implements IDataProvider {
|
||||
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting()
|
||||
|
@ -34,11 +39,18 @@ public class LangMerger implements IDataProvider {
|
|||
static final String CATEGORY_HEADER = "\t\"_\": \"->------------------------] %s [------------------------<-\",";
|
||||
|
||||
private DataGenerator gen;
|
||||
private List<Object> data;
|
||||
|
||||
private List<Object> mergedLangData;
|
||||
private Map<String, List<Object>> populatedLangData;
|
||||
private Map<String, Map<String, String>> allLocalizedEntries;
|
||||
private Map<String, MutableInt> missingTranslationTally;
|
||||
|
||||
public LangMerger(DataGenerator gen) {
|
||||
this.gen = gen;
|
||||
this.data = new ArrayList<>();
|
||||
this.mergedLangData = new ArrayList<>();
|
||||
this.allLocalizedEntries = new HashMap<>();
|
||||
this.populatedLangData = new HashMap<>();
|
||||
this.missingTranslationTally = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,11 +62,43 @@ public class LangMerger implements IDataProvider {
|
|||
public void act(DirectoryCache cache) throws IOException {
|
||||
Path path = this.gen.getOutputFolder()
|
||||
.resolve("assets/" + Create.ID + "/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);
|
||||
collectEntries();
|
||||
if (data.isEmpty())
|
||||
if (mergedLangData.isEmpty())
|
||||
return;
|
||||
save(cache, path);
|
||||
|
||||
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/" + Create.ID + "/lang/unfinished/" + key);
|
||||
save(cache, localization.getValue(), missingTranslationTally.get(key)
|
||||
.intValue(), populatedLangPath, "Populating " + key + " with missing entries...");
|
||||
}
|
||||
}
|
||||
|
||||
private void collectExistingEntries(Path path) throws IOException {
|
||||
|
@ -75,9 +119,9 @@ public class LangMerger implements IDataProvider {
|
|||
return;
|
||||
header = String.format(CATEGORY_HEADER, header);
|
||||
|
||||
data.add("\n");
|
||||
data.add(header);
|
||||
data.add("\n\n");
|
||||
writeData("\n");
|
||||
writeData(header);
|
||||
writeData("\n\n");
|
||||
|
||||
MutableObject<String> previousKey = new MutableObject<>("");
|
||||
jsonobject.entrySet()
|
||||
|
@ -88,12 +132,29 @@ public class LangMerger implements IDataProvider {
|
|||
.getAsString();
|
||||
if (!previousKey.getValue()
|
||||
.isEmpty() && shouldAddLineBreak(key, previousKey.getValue()))
|
||||
data.add("\n");
|
||||
data.add(new LangEntry(key, value));
|
||||
writeData("\n");
|
||||
writeEntry(key, value);
|
||||
previousKey.setValue(key);
|
||||
});
|
||||
|
||||
data.add("\n");
|
||||
writeData("\n");
|
||||
}
|
||||
|
||||
private void writeData(String data) {
|
||||
mergedLangData.add(data);
|
||||
populatedLangData.values()
|
||||
.forEach(l -> l.add(data));
|
||||
}
|
||||
|
||||
private void writeEntry(String key, String 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) {
|
||||
|
@ -108,11 +169,37 @@ public class LangMerger implements IDataProvider {
|
|||
String[] split2 = previousKey.split("\\.");
|
||||
if (split.length == 0 || split2.length == 0)
|
||||
return false;
|
||||
|
||||
|
||||
// Start new paragraph if keys before second point do not match
|
||||
return !split[0].equals(split2[0]);
|
||||
}
|
||||
|
||||
private List<Pair<String, JsonElement>> getAllLocalizationFiles() {
|
||||
ArrayList<Pair<String, JsonElement>> list = new ArrayList<>();
|
||||
|
||||
String filepath = "assets/" + Create.ID + "/lang/";
|
||||
try {
|
||||
InputStream resourceAsStream = Create.class.getClassLoader()
|
||||
.getResourceAsStream(filepath);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceAsStream));
|
||||
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)));
|
||||
}
|
||||
resourceAsStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void collectEntries() {
|
||||
for (AllLangPartials partial : AllLangPartials.values()) {
|
||||
String fileName = Lang.asId(partial.name());
|
||||
|
@ -124,16 +211,18 @@ public class LangMerger implements IDataProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private void save(DirectoryCache cache, Path target) throws IOException {
|
||||
String data = createString();
|
||||
data = JavaUnicodeEscaper.outsideOf(0, 0x7f)
|
||||
.translate(data);
|
||||
private void save(DirectoryCache cache, List<Object> dataIn, int missingKeys, Path target, String message)
|
||||
throws IOException {
|
||||
String data = createString(dataIn, missingKeys);
|
||||
// data = JavaUnicodeEscaper.outsideOf(0, 0x7f)
|
||||
// .translate(data);
|
||||
String hash = IDataProvider.HASH_FUNCTION.hashUnencodedChars(data)
|
||||
.toString();
|
||||
if (!Objects.equals(cache.getPreviousHash(target), hash) || !Files.exists(target)) {
|
||||
Files.createDirectories(target.getParent());
|
||||
|
||||
try (BufferedWriter bufferedwriter = Files.newBufferedWriter(target)) {
|
||||
Create.logger.info(message);
|
||||
bufferedwriter.write(data);
|
||||
bufferedwriter.close();
|
||||
}
|
||||
|
@ -142,9 +231,11 @@ public class LangMerger implements IDataProvider {
|
|||
cache.recordHash(target, hash);
|
||||
}
|
||||
|
||||
protected String createString() {
|
||||
protected String createString(List<Object> data, int missingKeys) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{\n");
|
||||
if (missingKeys != -1)
|
||||
builder.append("\t\"_\": \"Missing Localizations: " + missingKeys + "\"\n");
|
||||
data.forEach(builder::append);
|
||||
builder.append("\t\"_\": \"Thank you for translating Create!\"\n\n");
|
||||
builder.append("}");
|
||||
|
@ -169,4 +260,19 @@ public class LangMerger implements IDataProvider {
|
|||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
Hi there!
|
||||
Looking to contribute with a localization? Wonderful.
|
||||
You will find the english lang file here:
|
||||
https://github.com/Creators-of-Create/Create/blob/mc1.15/dev/src/generated/resources/assets/create/lang/en_us.json
|
||||
|
||||
You will find the full english lang file here:
|
||||
https://github.com/Creators-of-Create/Create/blob/mc1.15/dev/src/generated/resources/assets/create/lang/en_us.json
|
||||
|
||||
If you want to complete an outdated lang file, check out
|
||||
https://github.com/Creators-of-Create/Create/blob/mc1.15/dev/src/generated/resources/assets/create/lang/unfinished
|
||||
Missing entries have been added to these templates, marked with "UNLOCALIZED".
|
||||
These files are only there to help you, finished langs still belong in the folder this readme is in. Best of luck!
|
Loading…
Reference in a new issue