package lighthouse.utils;

import org.slf4j.*;

import javax.annotation.*;
import java.util.*;

import static gnu.gettext.GettextResource.*;

public class I18nUtil {
    private static final Logger log = LoggerFactory.getLogger(I18nUtil.class);
    @Nullable public static ResourceBundle locale;

    static {
        try {
            locale = ResourceBundle.getBundle("lighthouse.locale.lighthouse");
            log.info("Using language translations for {}", locale.getLocale());
        } catch (MissingResourceException e) {
            // Ignore.
        }
    }

    public static String tr(String s) {
        if (locale != null)
            return gettext(locale, s);
        else
            return s;
    }
}

@@ -20,16 +20,52 @@
 utils;%0A%0A
+import org.jetbrains.annotations.*;%0A
 import o
@@ -101,17 +101,24 @@
 otation.
-*
+Nullable
 ;%0Aimport
@@ -300,42 +300,800 @@
 le p
-ublic static ResourceBundle locale
+rivate static ResourceBundle locale;%0A%0A    public static ResourceBundle translations = new ResourceBundle() %7B%0A        @Override%0A        protected Object handleGetObject(String key) %7B%0A            if (locale == null)%0A                return key;%0A            else%0A                try %7B%0A                    return locale.getObject(key);%0A                %7D catch (MissingResourceException e) %7B%0A                    return key;%0A                %7D%0A        %7D%0A%0A        @Override%0A        public boolean containsKey(String key) %7B%0A            return true;%0A        %7D%0A%0A        @NotNull%0A        @Override%0A        public Enumeration%3CString%3E getKeys() %7B%0A            if (locale != null)%0A                return locale.getKeys();%0A            else%0A                return Collections.emptyEnumeration();%0A        %7D%0A    %7D
 ;%0A%0A 

Fix the case where a translation is missing and it's loaded via FXML with a custom ResourceBundle that never throws an error, it always returns the key (English string) if a real translation is missing.