fix(translate): don't initialize LibreTranslate if we can avoid it
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-11-19 13:04:59 +01:00
parent ef6c58e93d
commit 45f101f9ec
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 8 additions and 6 deletions

View File

@ -53,10 +53,12 @@ public interface TranslateService<T extends Language> {
} catch (URISyntaxException | IOException e) {
LibJf.LOGGER.error("Could not create Google Translate service", e);
}
try {
result.add(LibreTranslateService.get(TranslateConfig.libreTranslateHost));
} catch (TranslateException e) {
LibJf.LOGGER.error("Could not create LibreTranslate service", e);
if (TranslateConfig.libreTranslateHost != null) {
try {
result.add(LibreTranslateService.get(TranslateConfig.libreTranslateHost));
} catch (TranslateException e) {
LibJf.LOGGER.error("Could not create LibreTranslate service", e);
}
}
result.add(NoopTranslateService.INSTANCE);
return List.copyOf(result);

View File

@ -8,12 +8,12 @@ import io.gitlab.jfronny.libjf.translate.impl.libretranslate.LibreTranslateServi
public class TranslateConfig implements JfCustomConfig {
public static String translationService = GoogleTranslateService.NAME;
public static String libreTranslateHost = "https://translate.argosopentech.com";
public static String libreTranslateHost = null;
public static void ensureValid() {
if (translationService == null) translationService = GoogleTranslateService.NAME;
if (translationService.equals(LibreTranslateService.NAME) && libreTranslateHost == null || libreTranslateHost.isBlank())
libreTranslateHost = "https://translate.argosopentech.com";
translationService = GoogleTranslateService.NAME;
}
@Override