Translation Helper fixes
This commit is contained in:
parent
551bf6865c
commit
ceeb36fc2a
1 changed files with 50 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
||||||
package ru.bclib.util;
|
package ru.bclib.util;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -9,28 +9,34 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Collections;
|
import java.util.Set;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TranslationHelper {
|
public class TranslationHelper {
|
||||||
public static void printMissingNames(String modID) {
|
/**
|
||||||
List<String> missingNamesEn = Lists.newArrayList();
|
* Print English translation file lines. Translation is "auto-beautified" text (example "strange_thing" -> "Strange Thing").
|
||||||
List<String> missingNamesRu = Lists.newArrayList();
|
* @param modID {@link String} mod ID string.
|
||||||
|
*/
|
||||||
|
public static void printMissingEnNames(String modID) {
|
||||||
|
printMissingNames(modID, "en_us");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints translation file lines for specified language.
|
||||||
|
* @param modID {@link String} mod ID string;
|
||||||
|
* @param languageCode {@link String} language code (example "en_us", "ru_ru").
|
||||||
|
*/
|
||||||
|
public static void printMissingNames(String modID, String languageCode) {
|
||||||
|
Set<String> missingNames = Sets.newHashSet();
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
InputStream streamEn = TranslationHelper.class.getResourceAsStream("/assets/" + modID + "/lang/en_us.json");
|
InputStream inputStream = TranslationHelper.class.getResourceAsStream("/assets/" + modID + "/lang/" + languageCode + ".json");
|
||||||
InputStream streamRu = TranslationHelper.class.getResourceAsStream("/assets/" + modID + "/lang/ru_ru.json");
|
JsonObject translation = gson.fromJson(new InputStreamReader(inputStream), JsonObject.class);
|
||||||
JsonObject translationEn = gson.fromJson(new InputStreamReader(streamEn), JsonObject.class);
|
|
||||||
JsonObject translationRu = gson.fromJson(new InputStreamReader(streamRu), JsonObject.class);
|
|
||||||
|
|
||||||
Registry.BLOCK.forEach(block -> {
|
Registry.BLOCK.forEach(block -> {
|
||||||
if (Registry.BLOCK.getKey(block).getNamespace().equals(modID)) {
|
if (Registry.BLOCK.getKey(block).getNamespace().equals(modID)) {
|
||||||
String name = block.getName().getString();
|
String name = block.getName().getString();
|
||||||
if (!translationEn.has(name)) {
|
if (!translation.has(name)) {
|
||||||
missingNamesEn.add(name);
|
missingNames.add(name);
|
||||||
}
|
|
||||||
if (!translationRu.has(name)) {
|
|
||||||
missingNamesRu.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,11 +44,8 @@ public class TranslationHelper {
|
||||||
Registry.ITEM.forEach(item -> {
|
Registry.ITEM.forEach(item -> {
|
||||||
if (Registry.ITEM.getKey(item).getNamespace().equals(modID)) {
|
if (Registry.ITEM.getKey(item).getNamespace().equals(modID)) {
|
||||||
String name = item.getDescription().getString();
|
String name = item.getDescription().getString();
|
||||||
if (!translationEn.has(name)) {
|
if (!translation.has(name)) {
|
||||||
missingNamesEn.add(name);
|
missingNames.add(name);
|
||||||
}
|
|
||||||
if (!translationRu.has(name)) {
|
|
||||||
missingNamesRu.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -51,11 +54,8 @@ public class TranslationHelper {
|
||||||
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
|
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
|
||||||
if (id.getNamespace().equals(modID)) {
|
if (id.getNamespace().equals(modID)) {
|
||||||
String name = "biome." + modID + "." + id.getPath();
|
String name = "biome." + modID + "." + id.getPath();
|
||||||
if (!translationEn.has(name)) {
|
if (!translation.has(name)) {
|
||||||
missingNamesEn.add(name);
|
missingNames.add(name);
|
||||||
}
|
|
||||||
if (!translationRu.has(name)) {
|
|
||||||
missingNamesRu.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -64,44 +64,45 @@ public class TranslationHelper {
|
||||||
ResourceLocation id = Registry.ENTITY_TYPE.getKey(entity);
|
ResourceLocation id = Registry.ENTITY_TYPE.getKey(entity);
|
||||||
if (id.getNamespace().equals(modID)) {
|
if (id.getNamespace().equals(modID)) {
|
||||||
String name = "entity." + modID + "." + id.getPath();
|
String name = "entity." + modID + "." + id.getPath();
|
||||||
if (!translationEn.has(name)) {
|
if (!translation.has(name)) {
|
||||||
missingNamesEn.add(name);
|
missingNames.add(name);
|
||||||
}
|
|
||||||
if (!translationRu.has(name)) {
|
|
||||||
missingNamesRu.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!missingNamesEn.isEmpty() || !missingNamesRu.isEmpty()) {
|
if (!missingNames.isEmpty()) {
|
||||||
|
|
||||||
System.out.println("========================================");
|
System.out.println("========================================");
|
||||||
System.out.println(" MISSING NAMES LIST");
|
System.out.println(" MISSING NAMES LIST");
|
||||||
|
|
||||||
if (!missingNamesEn.isEmpty()) {
|
if (!missingNames.isEmpty()) {
|
||||||
Collections.sort(missingNamesEn);
|
if (languageCode.equals("en_us")) {
|
||||||
System.out.println("========================================");
|
System.out.println("========================================");
|
||||||
System.out.println(" ENGLISH");
|
System.out.println(" AUTO ENGLISH BEAUTIFICATION");
|
||||||
System.out.println("========================================");
|
System.out.println("========================================");
|
||||||
missingNamesEn.forEach((name) -> {
|
missingNames.stream().sorted().forEach(name -> {
|
||||||
System.out.println(" \"" + name + "\": \"" + fastTranslateEn(name) + "\",");
|
System.out.println(" \"" + name + "\": \"" + fastTranslateEn(name) + "\",");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (!missingNamesRu.isEmpty()) {
|
System.out.println("========================================");
|
||||||
Collections.sort(missingNamesRu);
|
System.out.println(" TEMPLATE: [" + languageCode + "]");
|
||||||
System.out.println("========================================");
|
System.out.println("========================================");
|
||||||
System.out.println(" RUSSIAN");
|
missingNames.stream().sorted().forEach(name -> {
|
||||||
System.out.println("========================================");
|
System.out.println(" \"" + name + "\": \"\",");
|
||||||
missingNamesRu.forEach((name) -> {
|
});
|
||||||
System.out.println(" \"" + name + "\": \"\",");
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("========================================");
|
System.out.println("========================================");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple fast text beautification (example "strange_thing" -> "Strange Thing").
|
||||||
|
* @param text {@link String} to process;
|
||||||
|
* @return {@link String} result.
|
||||||
|
*/
|
||||||
public static String fastTranslateEn(String text) {
|
public static String fastTranslateEn(String text) {
|
||||||
String[] words = text.substring(text.lastIndexOf('.') + 1).split("_");
|
String[] words = text.substring(text.lastIndexOf('.') + 1).split("_");
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue