From c93a60965fa773273bd302425f9885db5ab4acf5 Mon Sep 17 00:00:00 2001 From: JFronny Date: Fri, 10 May 2024 13:25:20 +0200 Subject: [PATCH] fix: respect useDefaultCache --- .../translater/transformer/CachingTransformer.java | 3 +-- .../translater/transformer/TranslatingTransformer.java | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/java/io/gitlab/jfronny/translater/transformer/CachingTransformer.java b/src/client/java/io/gitlab/jfronny/translater/transformer/CachingTransformer.java index 4b920c8..7e21afe 100644 --- a/src/client/java/io/gitlab/jfronny/translater/transformer/CachingTransformer.java +++ b/src/client/java/io/gitlab/jfronny/translater/transformer/CachingTransformer.java @@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collection; import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; @@ -80,7 +79,7 @@ public class CachingTransformer implements Transformer { } } //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"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Properties p = new Properties(); diff --git a/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java b/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java index a8344b2..69d84c9 100644 --- a/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java +++ b/src/client/java/io/gitlab/jfronny/translater/transformer/TranslatingTransformer.java @@ -37,7 +37,7 @@ public class TranslatingTransformer implements Transformer { for (String s : str.split("%")) { if (!f) { res.append("%"); - if (s.length() > 0) + if (!s.isEmpty()) res.append(s.charAt(0)).append(transform(s.substring(1)).replace("%", "")); } else res.append(transform(s)); @@ -71,7 +71,7 @@ public class TranslatingTransformer implements Transformer { } } 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"); return null; } @@ -90,7 +90,7 @@ public class TranslatingTransformer implements Transformer { private String translateMultiple(String str) throws TranslateException { Matcher m = SURROUNDING_SPACE_PATTERN.matcher(str); if (!m.find()) { - Translater.LOGGER.info("Skipping translation of \"" + str + "\""); + Translater.LOGGER.info("Skipping translation of \"{}\"", str); return str; } try { @@ -106,10 +106,10 @@ public class TranslatingTransformer implements Transformer { } 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 - Translater.LOGGER.info("Transformed: \"" + str + "\" to: \"" + currentState + "\""); + Translater.LOGGER.info("Transformed: \"{}\" to: \"{}\"", str, currentState); return currentState; } 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; } }