about 2 times faster, a more sane default cache
This commit is contained in:
parent
a36e2b8079
commit
ebef6df51b
@ -13,7 +13,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
version = "${project.mod_version}+${project.minecraft_version}"
|
||||
group = project.maven_group
|
||||
|
||||
dependencies {
|
||||
|
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
loader_version=0.8.8+build.202
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.1
|
||||
mod_version = 1.0.2
|
||||
maven_group = io.gitlab.jfronny
|
||||
archives_base_name = translater
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.gitlab.jfronny.translater;
|
||||
|
||||
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||||
import me.sargunvohra.mcmods.autoconfig1u.ConfigManager;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.*;
|
||||
@ -15,8 +17,10 @@ public abstract class CachingTransformer implements StringTransformer {
|
||||
return str;
|
||||
if (cache == null) {
|
||||
cache = new Properties();
|
||||
if (!ModInit.cfg.forceRegenerate) {
|
||||
if (ModInit.cfg.forceRegenerate) {
|
||||
ModInit.cfg.forceRegenerate = false;
|
||||
((ConfigManager<Cfg>) AutoConfig.getConfigHolder(Cfg.class)).save();
|
||||
} else {
|
||||
if (cacheFile.exists()) {
|
||||
try {
|
||||
FileInputStream inS = new FileInputStream(cacheFile);
|
||||
@ -26,7 +30,7 @@ public abstract class CachingTransformer implements StringTransformer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (!ModInit.cfg.breakFully && ModInit.cfg.rounds == 10) {
|
||||
if (!ModInit.cfg.breakFully && ModInit.cfg.rounds == 5) {
|
||||
try {
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
InputStream inS = classLoader.getResourceAsStream("namecache.ini");
|
||||
|
@ -7,11 +7,15 @@ import me.sargunvohra.mcmods.autoconfig1u.shadowed.blue.endless.jankson.Comment;
|
||||
@Config(name = "TranslaterCF")
|
||||
public class Cfg implements ConfigData {
|
||||
@Comment("NOTE: remove the cache after you change the config!\nRegenerating the cache can take up to 3 hours for vanilla (5000 strings)\nWatch the log when in doubt\n\nThe amount of times to translate each element")
|
||||
public int rounds = 10;
|
||||
public int rounds = 5;
|
||||
@Comment("Whether to fully break the texts content by translating from the wrong language (enable for complete breaking)")
|
||||
public boolean breakFully = false;
|
||||
@Comment("The API key for Yandex Translate (this is REQUIRED for updating the cache, since Yandex doesn't give them out for free anymore you might want to google \"trnsl.1.1.\" to find keys on the web)")
|
||||
public String key = "trnsl.1.1.20130811T164454Z.2facd8a3323b8111.e9f682063308aff12357de3c8a3260d6d6b71be7";
|
||||
@Comment("Enable this to get more information about what is happening currently - useful when caching takes long")
|
||||
public boolean verboseLogging = false;
|
||||
@Comment("The language to translate to - Leave empty for auto-detection (might break text even more)")
|
||||
public String targetLanguage = "en";
|
||||
@Comment("Use this if something is broken. This initiate the regeneration of the cache")
|
||||
public boolean forceRegenerate = false;
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ public class ModInit implements ModInitializer {
|
||||
}
|
||||
|
||||
public static void Log(String msg) {
|
||||
logger.log(Level.INFO, "[" + MOD_NAME + "]" + msg);
|
||||
logger.log(Level.INFO, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
public static void Warn(String msg) {
|
||||
logger.log(Level.WARN, "[" + MOD_NAME + "]" + msg);
|
||||
logger.log(Level.WARN, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
public static void LogDebug(String msg) {
|
||||
logger.log(Level.DEBUG, "[" + MOD_NAME + "]" + msg);
|
||||
logger.log(Level.DEBUG, "[" + MOD_NAME + "] " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,7 +11,13 @@ public class TransformingMap implements Map<String, String> {
|
||||
public TransformingMap(Map<String, String> m, StringTransformer t) {
|
||||
backer = m;
|
||||
transformer = t;
|
||||
for (String value : m.values()) {
|
||||
Collection<String> strings = m.values();
|
||||
int i = 0;
|
||||
for (String value : strings) {
|
||||
if (ModInit.cfg.verboseLogging) {
|
||||
i++;
|
||||
ModInit.Log("Transforming " + i + "/" + strings.size());
|
||||
}
|
||||
transformer.transform(value);
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,10 @@ public class YnTransformer extends CachingTransformer {
|
||||
try {
|
||||
if (!valid(str))
|
||||
return str;
|
||||
Language startLang = api.detectionApi().detect(str).orElse(Language.EN);
|
||||
|
||||
Language startLang = StringUtils.isAlpha(ModInit.cfg.targetLanguage) && ModInit.cfg.targetLanguage.length() == 2
|
||||
? Language.of(ModInit.cfg.targetLanguage)
|
||||
: api.detectionApi().detect(str).orElse(Language.EN);
|
||||
if (!valid(startLang.code())) {
|
||||
ModInit.Warn("Could not detect language for: " + str);
|
||||
ModInit.Warn("Defaulting to EN");
|
||||
@ -84,7 +87,8 @@ public class YnTransformer extends CachingTransformer {
|
||||
currentLang = newLang;
|
||||
}
|
||||
currentState = api.translationApi().translate(currentState, startLang).text();
|
||||
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
if (ModInit.cfg.verboseLogging)
|
||||
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
|
||||
return currentState;
|
||||
} catch (Exception e) {
|
||||
ModInit.Warn("Failed to break: " + str + " (" + str.length() + " characters)");
|
||||
|
@ -3,5 +3,7 @@
|
||||
"text.autoconfig.TranslaterCF.option.rounds": "Rounds",
|
||||
"text.autoconfig.TranslaterCF.option.breakFully": "Break Fully",
|
||||
"text.autoconfig.TranslaterCF.option.key": "API Key",
|
||||
"text.autoconfig.TranslaterCF.option.verboseLogging": "Verbose Logging",
|
||||
"text.autoconfig.TranslaterCF.option.targetLanguage": "Target Language",
|
||||
"text.autoconfig.TranslaterCF.option.forceRegenerate": "Force Regenerate"
|
||||
}
|
@ -33,5 +33,12 @@
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
"modupdater": {
|
||||
"strategy": "curseforge",
|
||||
"projectID": 394823
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user