fix: respect useDefaultCache

This commit is contained in:
Johannes Frohnmeyer 2024-05-10 13:25:20 +02:00
parent 60cfd016d6
commit c93a60965f
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 6 additions and 7 deletions

View File

@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -80,7 +79,7 @@ public class CachingTransformer implements Transformer {
} }
} }
//Save default cache if parameters are default //Save default cache if parameters are default
if (!Cfg.breakFully && Cfg.rounds == 5 && "en".equals(Cfg.targetLanguage) && !Cfg.forceRegenerate) { if (Cfg.useDefaultCache && !Cfg.breakFully && Cfg.rounds == 5 && "en".equals(Cfg.targetLanguage) && !Cfg.forceRegenerate) {
Translater.LOGGER.info("Initializing default cache"); Translater.LOGGER.info("Initializing default cache");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Properties p = new Properties(); Properties p = new Properties();

View File

@ -37,7 +37,7 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
for (String s : str.split("%")) { for (String s : str.split("%")) {
if (!f) { if (!f) {
res.append("%"); res.append("%");
if (s.length() > 0) if (!s.isEmpty())
res.append(s.charAt(0)).append(transform(s.substring(1)).replace("%", "")); res.append(s.charAt(0)).append(transform(s.substring(1)).replace("%", ""));
} else } else
res.append(transform(s)); res.append(transform(s));
@ -71,7 +71,7 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
} }
} }
catch (Exception e) { catch (Exception e) {
Translater.LOGGER.warn("Failed to transform: \"" + str + "\" (" + str.length() + " characters)"); Translater.LOGGER.warn("Failed to transform: \"{}\" ({} characters)", str, str.length());
Translater.LOGGER.warn("Please report this bug with the mod containing the lang file"); Translater.LOGGER.warn("Please report this bug with the mod containing the lang file");
return null; return null;
} }
@ -90,7 +90,7 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
private String translateMultiple(String str) throws TranslateException { private String translateMultiple(String str) throws TranslateException {
Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str); Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str);
if (!m.find()) { if (!m.find()) {
Translater.LOGGER.info("Skipping translation of \"" + str + "\""); Translater.LOGGER.info("Skipping translation of \"{}\"", str);
return str; return str;
} }
try { try {
@ -106,10 +106,10 @@ public class TranslatingTransformer<T extends Language> implements Transformer {
} }
currentState = ts.translate(currentState, currentLang, startLang == languageAuto ? languageEnglish : startLang); // Translate to starting language currentState = ts.translate(currentState, currentLang, startLang == languageAuto ? languageEnglish : startLang); // Translate to starting language
currentState = m.group(1) + currentState + m.group(3); // Add back surrounding white space currentState = m.group(1) + currentState + m.group(3); // Add back surrounding white space
Translater.LOGGER.info("Transformed: \"" + str + "\" to: \"" + currentState + "\""); Translater.LOGGER.info("Transformed: \"{}\" to: \"{}\"", str, currentState);
return currentState; return currentState;
} catch (Exception e) { } catch (Exception e) {
Translater.LOGGER.warn("Failed to break: \"" + m.group(2) + "\" (" + m.group(2).length() + " characters). Is your API key valid?"); Translater.LOGGER.warn("Failed to break: \"{}\" ({} characters). Is your API key valid?", m.group(2), m.group(2).length());
throw e; throw e;
} }
} }