diff --git a/build.gradle b/build.gradle index c5963cdfd..aa26ed057 100644 --- a/build.gradle +++ b/build.gradle @@ -137,43 +137,43 @@ poeditor { apiKey = System.getenv('POEDITOR_APIKEY') ?: 'xxx' projectId = '206221' - trans.add type:'properties', lang: 'bg', file: "${projectDir}/src/main/resources/sprache/Bulgarian.properties" - trans.add type:'properties', lang: 'ca', file: "${projectDir}/src/main/resources/sprache/Catalan.properties" - trans.add type:'properties', lang: 'hr', file: "${projectDir}/src/main/resources/sprache/Hrvatski(Croatian).properties" - trans.add type:'properties', lang: 'cs', file: "${projectDir}/src/main/resources/sprache/Czech.properties" - trans.add type:'properties', lang: 'da', file: "${projectDir}/src/main/resources/sprache/Danish.properties" - trans.add type:'properties', lang: 'nl', file: "${projectDir}/src/main/resources/sprache/Nederlands.properties" - trans.add type:'properties', lang: 'fi', file: "${projectDir}/src/main/resources/sprache/Finnish.properties" - trans.add type:'properties', lang: 'fr', file: "${projectDir}/src/main/resources/sprache/French.properties" - trans.add type:'properties', lang: 'de', file: "${projectDir}/src/main/resources/sprache/Deutsch.properties" - trans.add type:'properties', lang: 'el', file: "${projectDir}/src/main/resources/sprache/Greeklish.properties" - trans.add type:'properties', lang: 'he', file: "${projectDir}/src/main/resources/sprache/Hebrew.properties" //Hebrew - trans.add type:'properties', lang: 'hu', file: "${projectDir}/src/main/resources/sprache/Magyar.properties" //Hungarian - trans.add type:'properties', lang: 'it', file: "${projectDir}/src/main/resources/sprache/Italiano.properties" - trans.add type:'properties', lang: 'ko', file: "${projectDir}/src/main/resources/sprache/Hangul(Korean).properties" - trans.add type:'properties', lang: 'lv', file: "${projectDir}/src/main/resources/sprache/Latvija.properties" //Lettonie - trans.add type:'properties', lang: 'lt', file: "${projectDir}/src/main/resources/sprache/Lithuanian.properties" - trans.add type:'properties', lang: 'fa', file: "${projectDir}/src/main/resources/sprache/Persian.properties" - trans.add type:'properties', lang: 'pl', file: "${projectDir}/src/main/resources/sprache/Polish.properties" - trans.add type:'properties', lang: 'pt', file: "${projectDir}/src/main/resources/sprache/Portugues.properties" - trans.add type:'properties', lang: 'pt-br', file: "${projectDir}/src/main/resources/sprache/PortuguesBrasil.properties" - trans.add type:'properties', lang: 'ro', file: "${projectDir}/src/main/resources/sprache/Romanian.properties" - trans.add type:'properties', lang: 'ru', file: "${projectDir}/src/main/resources/sprache/Russian.properties" - trans.add type:'properties', lang: 'sr-cyrl', file: "${projectDir}/src/main/resources/sprache/Serbian(Cyrillic).properties" - trans.add type:'properties', lang: 'sk', file: "${projectDir}/src/main/resources/sprache/Slovak.properties" //Slovak - trans.add type:'properties', lang: 'es', file: "${projectDir}/src/main/resources/sprache/Spanish.properties" - trans.add type:'properties', lang: 'sv', file: "${projectDir}/src/main/resources/sprache/Svenska.properties" //Swedish - trans.add type:'properties', lang: 'tr', file: "${projectDir}/src/main/resources/sprache/Turkish.properties" - trans.add type:'properties', lang: 'no', file: "${projectDir}/src/main/resources/sprache/Norsk.properties" // Norwegian - trans.add type:'properties', lang: 'id', file: "${projectDir}/src/main/resources/sprache/Indonesian.properties" - trans.add type:'properties', lang: 'ja', file: "${projectDir}/src/main/resources/sprache/Japanese.properties" - trans.add type:'properties', lang: 'sl', file: "${projectDir}/src/main/resources/sprache/Slovenian.properties" - trans.add type:'properties', lang: 'uk', file: "${projectDir}/src/main/resources/sprache/Ukranian.properties" - trans.add type:'properties', lang: 'ka', file: "${projectDir}/src/main/resources/sprache/Georgian.properties" - trans.add type:'properties', lang: 'zh-CN', file: "${projectDir}/src/main/resources/sprache/Chinese.properties" - trans.add type:'properties', lang: 'gl', file: "${projectDir}/src/main/resources/sprache/Galego.properties" // Galician - trans.add type:'properties', lang: 'nl-be', file: "${projectDir}/src/main/resources/sprache/Vlaams.properties" // Flemish - trans.add type:'properties', lang: 'es-ar', file: "${projectDir}/src/main/resources/sprache/Spanish(AR).properties" // Argentina + trans.add type:'properties', lang: 'bg', file: "${projectDir}/src/main/resources/language/Bulgarian.properties" + trans.add type:'properties', lang: 'ca', file: "${projectDir}/src/main/resources/language/Catalan.properties" + trans.add type:'properties', lang: 'hr', file: "${projectDir}/src/main/resources/language/Hrvatski(Croatian).properties" + trans.add type:'properties', lang: 'cs', file: "${projectDir}/src/main/resources/language/Czech.properties" + trans.add type:'properties', lang: 'da', file: "${projectDir}/src/main/resources/language/Danish.properties" + trans.add type:'properties', lang: 'nl', file: "${projectDir}/src/main/resources/language/Nederlands.properties" + trans.add type:'properties', lang: 'fi', file: "${projectDir}/src/main/resources/language/Finnish.properties" + trans.add type:'properties', lang: 'fr', file: "${projectDir}/src/main/resources/language/French.properties" + trans.add type:'properties', lang: 'de', file: "${projectDir}/src/main/resources/language/German.properties" + trans.add type:'properties', lang: 'el', file: "${projectDir}/src/main/resources/language/Greeklish.properties" + trans.add type:'properties', lang: 'he', file: "${projectDir}/src/main/resources/language/Hebrew.properties" //Hebrew + trans.add type:'properties', lang: 'hu', file: "${projectDir}/src/main/resources/language/Magyar.properties" //Hungarian + trans.add type:'properties', lang: 'it', file: "${projectDir}/src/main/resources/language/Italiano.properties" + trans.add type:'properties', lang: 'ko', file: "${projectDir}/src/main/resources/language/Hangul(Korean).properties" + trans.add type:'properties', lang: 'lv', file: "${projectDir}/src/main/resources/language/Latvija.properties" //Lettonie + trans.add type:'properties', lang: 'lt', file: "${projectDir}/src/main/resources/language/Lithuanian.properties" + trans.add type:'properties', lang: 'fa', file: "${projectDir}/src/main/resources/language/Persian.properties" + trans.add type:'properties', lang: 'pl', file: "${projectDir}/src/main/resources/language/Polish.properties" + trans.add type:'properties', lang: 'pt', file: "${projectDir}/src/main/resources/language/Portugues.properties" + trans.add type:'properties', lang: 'pt-br', file: "${projectDir}/src/main/resources/language/PortuguesBrasil.properties" + trans.add type:'properties', lang: 'ro', file: "${projectDir}/src/main/resources/language/Romanian.properties" + trans.add type:'properties', lang: 'ru', file: "${projectDir}/src/main/resources/language/Russian.properties" + trans.add type:'properties', lang: 'sr-cyrl', file: "${projectDir}/src/main/resources/language/Serbian(Cyrillic).properties" + trans.add type:'properties', lang: 'sk', file: "${projectDir}/src/main/resources/language/Slovak.properties" //Slovak + trans.add type:'properties', lang: 'es', file: "${projectDir}/src/main/resources/language/Spanish.properties" + trans.add type:'properties', lang: 'sv', file: "${projectDir}/src/main/resources/language/Svenska.properties" //Swedish + trans.add type:'properties', lang: 'tr', file: "${projectDir}/src/main/resources/language/Turkish.properties" + trans.add type:'properties', lang: 'no', file: "${projectDir}/src/main/resources/language/Norsk.properties" // Norwegian + trans.add type:'properties', lang: 'id', file: "${projectDir}/src/main/resources/language/Indonesian.properties" + trans.add type:'properties', lang: 'ja', file: "${projectDir}/src/main/resources/language/Japanese.properties" + trans.add type:'properties', lang: 'sl', file: "${projectDir}/src/main/resources/language/Slovenian.properties" + trans.add type:'properties', lang: 'uk', file: "${projectDir}/src/main/resources/language/Ukranian.properties" + trans.add type:'properties', lang: 'ka', file: "${projectDir}/src/main/resources/language/Georgian.properties" + trans.add type:'properties', lang: 'zh-CN', file: "${projectDir}/src/main/resources/language/Chinese.properties" + trans.add type:'properties', lang: 'gl', file: "${projectDir}/src/main/resources/language/Galego.properties" // Galician + trans.add type:'properties', lang: 'nl-be', file: "${projectDir}/src/main/resources/language/Vlaams.properties" // Flemish + trans.add type:'properties', lang: 'es-ar', file: "${projectDir}/src/main/resources/language/Spanish(AR).properties" // Argentina } @@ -463,15 +463,15 @@ tasks.register("createLanguageFileList") { outputs.upToDateWhen { false } def lTranslationFiles = [] - fileTree(dir: "${projectDir}/src/main/resources/sprache", include: '*.properties').visit { + fileTree(dir: "${projectDir}/src/main/resources/language", include: '*.properties').visit { FileVisitDetails details -> lTranslationFiles << details.file.name } doLast { - println("listing available translation in ${projectDir}/src/main/resources/sprache") + println("listing available translation in ${projectDir}/src/main/resources/language") lTranslationFiles = lTranslationFiles.collect { it.take(it.lastIndexOf('.'))} lTranslationFiles.each {out.println it} - File lstFile = new File("${projectDir}/src/main/resources/sprache/ListLanguages.txt") + File lstFile = new File("${projectDir}/src/main/resources/language/ListLanguages.txt") lstFile.withWriter{ out -> lTranslationFiles.each {out.println it} } } } diff --git a/src/main/java/core/HO.java b/src/main/java/core/HO.java index 22d48b662..4a83d7834 100644 --- a/src/main/java/core/HO.java +++ b/src/main/java/core/HO.java @@ -181,9 +181,9 @@ public static void main(String[] args) { } // Check if language file available - interruptionWindow.setInfoText(4, "Check Languagefiles"); + interruptionWindow.setInfoText(4, "Check Language files"); HOVerwaltung.checkLanguageFile(UserParameter.instance().sprachDatei); - HOVerwaltung.instance().setResource(UserParameter.instance().sprachDatei); + HOVerwaltung.instance().setTranslator(UserParameter.instance().sprachDatei); if (DBManager.instance().isFirstStart()) { interruptionWindow.setVisible(false); diff --git a/src/main/java/core/file/xml/XMLMatchOrderParserNew.java b/src/main/java/core/file/xml/XMLMatchOrderParserNew.java index 7f0778de9..3c322aa98 100644 --- a/src/main/java/core/file/xml/XMLMatchOrderParserNew.java +++ b/src/main/java/core/file/xml/XMLMatchOrderParserNew.java @@ -83,7 +83,7 @@ private MatchRoleID getPosition(Node playerNode) { * @param args */ public static void main(String[] args) { - HOVerwaltung.instance().setResource(UserParameter.instance().sprachDatei); + HOVerwaltung.instance().setTranslator(UserParameter.instance().sprachDatei); File file = new File( "/home/chr/tmp/matchorders_version_1_8_matchID_353869167_isYouth_false.xml"); new XMLMatchOrderParserNew(XMLManager.parseFile(file)); diff --git a/src/main/java/core/gui/language/LanguageComboBoxModel.java b/src/main/java/core/gui/language/LanguageComboBoxModel.java index 9f71172a8..dac1938d5 100644 --- a/src/main/java/core/gui/language/LanguageComboBoxModel.java +++ b/src/main/java/core/gui/language/LanguageComboBoxModel.java @@ -86,7 +86,7 @@ public void characters(char ch[], int start, int length) throws SAXException { }; - URL languages = this.getClass().getClassLoader().getResource("sprache/languages.xml"); + URL languages = this.getClass().getClassLoader().getResource("language/languages.xml"); saxParser.parse(languages.getPath(), handler); } catch (Exception e) { diff --git a/src/main/java/core/gui/language/LanguageTableModel.java b/src/main/java/core/gui/language/LanguageTableModel.java index f20802e89..08c7b4b76 100644 --- a/src/main/java/core/gui/language/LanguageTableModel.java +++ b/src/main/java/core/gui/language/LanguageTableModel.java @@ -1,8 +1,11 @@ package core.gui.language; +import core.model.Translator; import core.util.HOLogger; -import core.util.UTF8Control; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableModel; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; @@ -19,11 +22,6 @@ import java.util.Map; import java.util.ResourceBundle; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableModel; - /** * This class represents the table model for editing language resource files. * @author edswifa @@ -46,7 +44,7 @@ public LanguageTableModel() { LinkedHashMap map = new LinkedHashMap(); - URL englishPath = this.getClass().getClassLoader().getResource("sprache/English.properties"); + URL englishPath = this.getClass().getClassLoader().getResource("language/English.properties"); FileInputStream fis = null; try { @@ -88,8 +86,8 @@ public LanguageTableModel(String languageName) { this.isDestinationFile = true; this.langauageName = languageName; - ResourceBundle englishBundle = ResourceBundle.getBundle("sprache.English", new UTF8Control()); - ResourceBundle destBundle = ResourceBundle.getBundle("sprache." + languageName, new UTF8Control()); + ResourceBundle englishBundle = Translator.loadDefault().getResourceBundle(); + ResourceBundle destBundle = Translator.load(languageName).getResourceBundle(); Iterator rbKeys = this.keys.iterator(); String value = null; @@ -158,7 +156,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { * Save the table model back to a properties file */ public void save() { - StringBuilder fileName = new StringBuilder("sprache/"); + StringBuilder fileName = new StringBuilder("language/"); fileName.append(this.langauageName); fileName.append(".properties"); URL destinationPath = this.getClass().getClassLoader().getResource(fileName.toString()); diff --git a/src/main/java/core/model/HOVerwaltung.java b/src/main/java/core/model/HOVerwaltung.java index feca1d5f1..895c86e4f 100644 --- a/src/main/java/core/model/HOVerwaltung.java +++ b/src/main/java/core/model/HOVerwaltung.java @@ -1,6 +1,5 @@ package core.model; - import core.db.DBManager; import core.file.FileLoader; import core.file.hrf.HRF; @@ -8,16 +7,14 @@ import core.gui.RefreshManager; import core.util.HODateTime; import core.util.HOLogger; -import core.util.Languages; -import core.util.UTF8Control; + import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.InputStream; import java.sql.Timestamp; -import java.text.MessageFormat; import java.time.temporal.ChronoUnit; import java.util.Date; -import java.util.Locale; +import java.util.Optional; import java.util.ResourceBundle; public class HOVerwaltung { @@ -29,9 +26,7 @@ public class HOVerwaltung { /** das Model */ protected HOModel m_clHoModel; - /** Resource */ - protected ResourceBundle languageBundle; - protected Locale m_locale; + private Translator translator = null; public static boolean isNewModel(HOModel homodel) { return (homodel != null && ((instance().getModel() == null) || @@ -87,23 +82,28 @@ public static HOVerwaltung instance() { return m_clInstance; } + /** + * @deprecated Provided for compatibility. Please use {@link #setTranslator(String)} instead. + */ + @Deprecated(since = "9.0", forRemoval = true) public void setResource(String pfad) { + setTranslator(pfad); + } + + public void setTranslator(String language) { try { - languageBundle = ResourceBundle.getBundle("sprache." + pfad, new UTF8Control()); - m_locale = Languages.lookup(UserParameter.instance().sprachDatei).getLocale(); - } - catch (UnsupportedOperationException e) { - // ResourceBundle.Control not supported in named modules in JDK9+ - languageBundle = ResourceBundle.getBundle("sprache." + pfad); - m_locale = Languages.lookup(UserParameter.instance().sprachDatei).getLocale(); - } catch (Exception e) { + translator = Translator.load(language); + } catch (RuntimeException e) { HOLogger.instance().log(getClass(), e); } - } + /** + * @deprecated Provided for compatibility. Will be removed without substitution! + */ + @Deprecated(since = "9.0", forRemoval = true) public ResourceBundle getResource() { - return languageBundle; + return Optional.ofNullable(translator).map(Translator::getResourceBundle).orElse(null); } /** @@ -205,33 +205,7 @@ protected HOModel loadModel(int id) { * language files */ public String getLanguageString(String key) { - String temp = null; - try { - if (languageBundle != null) { - temp = languageBundle.getString(key); - } - } catch (Exception e) { - // Do nothing, it just throws error if key is missing. - } - if (temp != null) - return temp; - // Search in english.properties if nothing found and active language not - // english - if (!UserParameter.instance().sprachDatei.equalsIgnoreCase("english")) { - ResourceBundle tempBundle = ResourceBundle.getBundle("sprache.English", new UTF8Control()); - - try { - temp = tempBundle.getString(key); - } catch (Exception e) { - // Ignore - } - - if (temp != null) - return temp; - } - - HOLogger.instance().warning(getClass(), "getLanguageString: '" + key + "' not found!"); - return "!" + key + "!"; + return translator.translate(key); } /** @@ -245,36 +219,7 @@ public String getLanguageString(String key) { * replaced by the given value(s). */ public String getLanguageString(String key, Object... values) { - - String str = getLanguageString(key); - - MessageFormat formatter = new MessageFormat(""); - formatter.setLocale(m_locale); - formatter.applyPattern(str); - - return formatter.format(values); - } - - public static String[] getLanguageFileNames() { - String[] files = null; - - try { - java.io.InputStream is = HOVerwaltung.class.getClassLoader().getResourceAsStream("sprache/ListLanguages.txt"); - assert is != null; - java.util.Scanner s = new java.util.Scanner(is); - java.util.ArrayList llist = new java.util.ArrayList<>(); - while (s.hasNext()){ - llist.add(s.next()); - } - s.close(); - - files = llist.toArray(new String[0]); - - } catch (Exception e) { - HOLogger.instance().log(HOVerwaltung.class, e); - } - - return files; + return translator.translate(key, values); } /** @@ -282,22 +227,29 @@ public static String[] getLanguageFileNames() { */ public static void checkLanguageFile(String languageFilename) { try { - final InputStream translationFile = FileLoader.instance().getFileInputStream("sprache/" + languageFilename + ".properties"); - if (translationFile != null) { + if (Translator.isAvailable(languageFilename)) { HOLogger.instance().info(HOVerwaltung.class, "language used for interface is: " + languageFilename); } else{ - HOLogger.instance().error(HOVerwaltung.class, "language set for interface (" + languageFilename +") can't be loaded ... reverting to English !"); - UserParameter.instance().sprachDatei = "English"; + HOLogger.instance().error(HOVerwaltung.class, "language set for interface (" + languageFilename + ") can't be loaded ... reverting to " + Translator.LANGUAGE_DEFAULT + " !"); + UserParameter.instance().sprachDatei = Translator.LANGUAGE_DEFAULT; } } catch (Exception e) { - HOLogger.instance().error(HOVerwaltung.class, "language set for interface (" + languageFilename +") can't be loaded ... reverting to English !" + " " + e); - UserParameter.instance().sprachDatei = "English"; + HOLogger.instance().error(HOVerwaltung.class, "language set for interface (" + languageFilename + ") can't be loaded ... reverting to " + Translator.LANGUAGE_DEFAULT + " !" + " " + e); + UserParameter.instance().sprachDatei = Translator.LANGUAGE_DEFAULT; } } - public void setLanguageBundle(ResourceBundle bundle) { - this.languageBundle = bundle; + /** + * @deprecated Provided for compatibility. Please use {@link #clearTranslator()} instead. + */ + @Deprecated(since = "9.0", forRemoval = true) + public void clearLanguageBundle() { + clearTranslator(); + } + + public void clearTranslator() { + translator = null; } } diff --git a/src/main/java/core/model/Translator.java b/src/main/java/core/model/Translator.java new file mode 100644 index 000000000..d3ac3371c --- /dev/null +++ b/src/main/java/core/model/Translator.java @@ -0,0 +1,151 @@ +package core.model; + +import core.file.FileLoader; +import core.util.HOLogger; +import core.util.Languages; +import core.util.UTF8Control; + +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.Scanner; + +public class Translator { + + public static final String LANGUAGE_RESOURCE_PATH = "language"; + public static final String LANGUAGE_DEFAULT = "English"; + public static final String LANGUAGE_FILE_EXTENSION = "properties"; + + private static final String LANGUAGE_SUPPORTED_LANGUAGES_FILENAME = "ListLanguages.txt"; + private static final String PATH_SEPARATOR = "/"; + private static final String EXTENSION_SEPARATOR = "."; + + private final String language; + private final ResourceBundle resourceBundle; + private final Locale locale; + + public Translator(String language, ResourceBundle resourceBundle, Locale locale) { + this.language = language; + this.resourceBundle = resourceBundle; + this.locale = locale; + } + + public static String[] getSupportedLanguages() { + String[] files = null; + + try { + InputStream is = HOVerwaltung.class.getClassLoader().getResourceAsStream(LANGUAGE_RESOURCE_PATH + PATH_SEPARATOR + LANGUAGE_SUPPORTED_LANGUAGES_FILENAME); + assert is != null; + Scanner s = new Scanner(is); + ArrayList list = new ArrayList<>(); + while (s.hasNext()) { + list.add(s.next()); + } + s.close(); + + files = list.toArray(new String[0]); + + } catch (Exception e) { + HOLogger.instance().log(HOVerwaltung.class, e); + } + + return files; + } + + public static boolean isAvailable(String language) { + InputStream translationFile = FileLoader.instance().getFileInputStream(LANGUAGE_RESOURCE_PATH + PATH_SEPARATOR + language + EXTENSION_SEPARATOR + LANGUAGE_FILE_EXTENSION); + return translationFile != null; + } + + public static Translator load(String language) { + return new Translator(language, getResourceBundle(language), Languages.lookup(language).getLocale()); + } + + private static ResourceBundle getResourceBundle(String language) { + final String baseName = LANGUAGE_RESOURCE_PATH + EXTENSION_SEPARATOR + language; + try { + return ResourceBundle.getBundle(baseName, new UTF8Control()); + } catch (UnsupportedOperationException e) { + // ResourceBundle.Control not supported in named modules in JDK9+ + return ResourceBundle.getBundle(baseName); + } + } + + public static Translator loadDefault() { + return load(LANGUAGE_DEFAULT); + } + + public String getLanguage() { + return this.language; + } + + public ResourceBundle getResourceBundle() { + return this.resourceBundle; + } + + public Locale getLocale() { + return this.locale; + } + + /** + * Returns the String connected to the active language file or connected to the english language file. Returns !key! + * if the key can not be found. + * + * @param key Key to be searched in language files + * + * @return String connected to the key or !key! if nothing can be found in language files + */ + public String translate(String key) { + String temp = null; + try { + if (resourceBundle != null) { + temp = resourceBundle.getString(key); + } + } catch (RuntimeException e) { + // Do nothing, it just throws error if key is missing. + } + if (temp != null) + return temp; + + // Search in properties of default language if nothing found and active language not the default + if (!isDefaultLanguage()) { + ResourceBundle tempBundle = loadDefault().getResourceBundle(); + + try { + temp = tempBundle.getString(key); + } catch (RuntimeException e) { + // Ignore + } + + if (temp != null) + return temp; + } + + HOLogger.instance().warning(getClass(), "translate: '" + key + "' not found!"); + return "!" + key + "!"; + } + + private boolean isDefaultLanguage() { + return getLanguage().equalsIgnoreCase(LANGUAGE_DEFAULT); + } + + /** + * Gets a parameterized message for the current language. + * + * @param key the key for the message in the language file. + * @param values the values for the message + * + * @return the message for the specified key where the placeholders are replaced by the given value(s). + */ + public String translate(String key, Object... values) { + String str = translate(key); + + MessageFormat formatter = new MessageFormat(""); + formatter.setLocale(locale); + formatter.applyPattern(str); + + return formatter.format(values); + } +} diff --git a/src/main/java/core/model/UserParameter.java b/src/main/java/core/model/UserParameter.java index e02e30e4a..2921b778f 100644 --- a/src/main/java/core/model/UserParameter.java +++ b/src/main/java/core/model/UserParameter.java @@ -30,6 +30,9 @@ public final class UserParameter extends Configuration { public static final int POSITIONNAMES_SHORT = 0; public static final int POSITIONNAMES_LONG = 1; + private static final String LANGUAGE_DEUTSCH_OBSOLETE = "Deutsch"; + private static final String LANGUAGE_GERMAN = "German"; + //~ Instance fields ---------------------------------------------------------------------------- public String AccessToken = ""; @@ -53,7 +56,7 @@ public final class UserParameter extends Configuration { /** * Name of language */ - public String sprachDatei = "English"; + public String sprachDatei = Translator.LANGUAGE_DEFAULT; /** * is proxy activ */ @@ -661,7 +664,7 @@ public void setValues(Map values) { hrfImport_HRFPath = getStringValue(values, "hrfImport_HRFPath"); matchLineupImport_Path = getStringValue(values, "matchLineupImport_Path"); spielPlanImport_Path = getStringValue(values, "spielPlanImport_Path"); - sprachDatei = getStringValue(values, "sprachDatei"); + sprachDatei = readLegacyLanguage(getStringValue(values, "sprachDatei")); skin = getStringValue(values, "skin"); ProxyAktiv = getBooleanValue(values, "ProxyAktiv"); @@ -896,4 +899,18 @@ public void setValues(Map values) { matchPredictionDialog_Width = getIntValue(values, "matchPredictionDialog_Width"); matchPredictionDialog_Height = getIntValue(values, "matchPredictionDialog_Height"); } + + /** + * Reads the legacy language {@code legacyLanguage} and returns the language. + * + * @return the language + * + * @since 9.0 - added due to renaming the language {@code Deutsch} to {@code German}. + */ + private static String readLegacyLanguage(String legacyLanguage) { + if (LANGUAGE_DEUTSCH_OBSOLETE.equalsIgnoreCase(legacyLanguage)) { + return LANGUAGE_GERMAN; + } + return legacyLanguage; + } } \ No newline at end of file diff --git a/src/main/java/core/option/GeneralSettingsPanel.java b/src/main/java/core/option/GeneralSettingsPanel.java index d39ba8844..ad8d0fe5d 100644 --- a/src/main/java/core/option/GeneralSettingsPanel.java +++ b/src/main/java/core/option/GeneralSettingsPanel.java @@ -5,6 +5,7 @@ import core.gui.theme.Theme; import core.gui.theme.ThemeManager; import core.model.HOVerwaltung; +import core.model.Translator; import core.model.UserParameter; import core.util.DateTimeUtils; import core.util.HOLogger; @@ -112,7 +113,7 @@ private void initComponents() { m_jcbSkin.addItemListener(this); add(m_jcbSkin); - final String[] sprachdateien = HOVerwaltung.getLanguageFileNames(); + final String[] sprachdateien = Translator.getSupportedLanguages(); try { java.util.Arrays.sort(sprachdateien); } catch (Exception ignored) { diff --git a/src/main/java/core/option/InitOptionsDialog.java b/src/main/java/core/option/InitOptionsDialog.java index 596e4d526..f6ca19b8d 100644 --- a/src/main/java/core/option/InitOptionsDialog.java +++ b/src/main/java/core/option/InitOptionsDialog.java @@ -1,6 +1,8 @@ // %4025553032:de.hattrickorganizer.gui.menu.option% package core.option; +import core.model.Translator; + import java.awt.BorderLayout; import java.awt.GridLayout; @@ -56,7 +58,7 @@ private void initComponents() { optionspanel.add(new JLabel("Language")); - final String[] sprachdateien = core.model.HOVerwaltung.getLanguageFileNames(); + final String[] sprachdateien = Translator.getSupportedLanguages(); try { java.util.Arrays.sort(sprachdateien); diff --git a/src/main/java/module/teamAnalyzer/vo/MatchRating.java b/src/main/java/module/teamAnalyzer/vo/MatchRating.java index 86fb2a5ef..5916ae190 100644 --- a/src/main/java/module/teamAnalyzer/vo/MatchRating.java +++ b/src/main/java/module/teamAnalyzer/vo/MatchRating.java @@ -1,8 +1,9 @@ package module.teamAnalyzer.vo; import core.model.HOVerwaltung; +import core.model.Translator; import core.model.match.IMatchDetails; -import core.util.UTF8Control; + import java.util.ResourceBundle; import static core.model.match.IMatchDetails.TAKTIK_NORMAL; @@ -44,7 +45,7 @@ public void setAttitude(String attitude) { public static int AttitudeStringToInt(String attitude) { attitude = attitude.toLowerCase(); - ResourceBundle englishBundle = ResourceBundle.getBundle("sprache.English", new UTF8Control()); + ResourceBundle englishBundle = Translator.loadDefault().getResourceBundle(); HOVerwaltung hoi = HOVerwaltung.instance(); String english_attitudeType = englishBundle.getString("ls.team.teamattitude.normal").toLowerCase(); @@ -80,7 +81,7 @@ public void setTacticType(String tacticType) { public static int TacticTypeStringToInt(String tacticType) { tacticType = tacticType.toLowerCase(); - ResourceBundle englishBundle = ResourceBundle.getBundle("sprache.English", new UTF8Control()); + ResourceBundle englishBundle = Translator.loadDefault().getResourceBundle();; HOVerwaltung hoi = HOVerwaltung.instance(); String english_tactictype = englishBundle.getString("ls.team.tactic.normal").toLowerCase(); diff --git a/src/main/resources/sprache/Bulgarian.properties b/src/main/resources/language/Bulgarian.properties similarity index 100% rename from src/main/resources/sprache/Bulgarian.properties rename to src/main/resources/language/Bulgarian.properties diff --git a/src/main/resources/sprache/Catalan.properties b/src/main/resources/language/Catalan.properties similarity index 100% rename from src/main/resources/sprache/Catalan.properties rename to src/main/resources/language/Catalan.properties diff --git a/src/main/resources/sprache/Chinese.properties b/src/main/resources/language/Chinese.properties similarity index 100% rename from src/main/resources/sprache/Chinese.properties rename to src/main/resources/language/Chinese.properties diff --git a/src/main/resources/sprache/Czech.properties b/src/main/resources/language/Czech.properties similarity index 100% rename from src/main/resources/sprache/Czech.properties rename to src/main/resources/language/Czech.properties diff --git a/src/main/resources/sprache/Danish.properties b/src/main/resources/language/Danish.properties similarity index 100% rename from src/main/resources/sprache/Danish.properties rename to src/main/resources/language/Danish.properties diff --git a/src/main/resources/sprache/English.properties b/src/main/resources/language/English.properties similarity index 100% rename from src/main/resources/sprache/English.properties rename to src/main/resources/language/English.properties diff --git a/src/main/resources/sprache/Finnish.properties b/src/main/resources/language/Finnish.properties similarity index 100% rename from src/main/resources/sprache/Finnish.properties rename to src/main/resources/language/Finnish.properties diff --git a/src/main/resources/sprache/French.properties b/src/main/resources/language/French.properties similarity index 100% rename from src/main/resources/sprache/French.properties rename to src/main/resources/language/French.properties diff --git a/src/main/resources/sprache/Galego.properties b/src/main/resources/language/Galego.properties similarity index 100% rename from src/main/resources/sprache/Galego.properties rename to src/main/resources/language/Galego.properties diff --git a/src/main/resources/sprache/Georgian.properties b/src/main/resources/language/Georgian.properties similarity index 100% rename from src/main/resources/sprache/Georgian.properties rename to src/main/resources/language/Georgian.properties diff --git a/src/main/resources/sprache/Deutsch.properties b/src/main/resources/language/German.properties similarity index 100% rename from src/main/resources/sprache/Deutsch.properties rename to src/main/resources/language/German.properties diff --git a/src/main/resources/sprache/Greeklish.properties b/src/main/resources/language/Greeklish.properties similarity index 100% rename from src/main/resources/sprache/Greeklish.properties rename to src/main/resources/language/Greeklish.properties diff --git a/src/main/resources/sprache/Hangul(Korean).properties b/src/main/resources/language/Hangul(Korean).properties similarity index 100% rename from src/main/resources/sprache/Hangul(Korean).properties rename to src/main/resources/language/Hangul(Korean).properties diff --git a/src/main/resources/sprache/Hebrew.properties b/src/main/resources/language/Hebrew.properties similarity index 100% rename from src/main/resources/sprache/Hebrew.properties rename to src/main/resources/language/Hebrew.properties diff --git a/src/main/resources/sprache/Hrvatski(Croatian).properties b/src/main/resources/language/Hrvatski(Croatian).properties similarity index 100% rename from src/main/resources/sprache/Hrvatski(Croatian).properties rename to src/main/resources/language/Hrvatski(Croatian).properties diff --git a/src/main/resources/sprache/Indonesian.properties b/src/main/resources/language/Indonesian.properties similarity index 100% rename from src/main/resources/sprache/Indonesian.properties rename to src/main/resources/language/Indonesian.properties diff --git a/src/main/resources/sprache/Italiano.properties b/src/main/resources/language/Italiano.properties similarity index 100% rename from src/main/resources/sprache/Italiano.properties rename to src/main/resources/language/Italiano.properties diff --git a/src/main/resources/sprache/Japanese.properties b/src/main/resources/language/Japanese.properties similarity index 100% rename from src/main/resources/sprache/Japanese.properties rename to src/main/resources/language/Japanese.properties diff --git a/src/main/resources/sprache/Latvija.properties b/src/main/resources/language/Latvija.properties similarity index 100% rename from src/main/resources/sprache/Latvija.properties rename to src/main/resources/language/Latvija.properties diff --git a/src/main/resources/sprache/Legacy/Serbian (latin).properties b/src/main/resources/language/Legacy/Serbian (latin).properties similarity index 100% rename from src/main/resources/sprache/Legacy/Serbian (latin).properties rename to src/main/resources/language/Legacy/Serbian (latin).properties diff --git a/src/main/resources/sprache/Legacy/Spanish(AR).properties b/src/main/resources/language/Legacy/Spanish(AR).properties similarity index 100% rename from src/main/resources/sprache/Legacy/Spanish(AR).properties rename to src/main/resources/language/Legacy/Spanish(AR).properties diff --git a/src/main/resources/sprache/ListLanguages.txt b/src/main/resources/language/ListLanguages.txt similarity index 97% rename from src/main/resources/sprache/ListLanguages.txt rename to src/main/resources/language/ListLanguages.txt index cc05d4052..a40567595 100644 --- a/src/main/resources/sprache/ListLanguages.txt +++ b/src/main/resources/language/ListLanguages.txt @@ -3,12 +3,12 @@ Catalan Chinese Czech Danish -Deutsch English Finnish French Galego Georgian +German Greeklish Hangul(Korean) Hebrew diff --git a/src/main/resources/sprache/Lithuanian.properties b/src/main/resources/language/Lithuanian.properties similarity index 100% rename from src/main/resources/sprache/Lithuanian.properties rename to src/main/resources/language/Lithuanian.properties diff --git a/src/main/resources/sprache/Magyar.properties b/src/main/resources/language/Magyar.properties similarity index 100% rename from src/main/resources/sprache/Magyar.properties rename to src/main/resources/language/Magyar.properties diff --git a/src/main/resources/sprache/Nederlands.properties b/src/main/resources/language/Nederlands.properties similarity index 100% rename from src/main/resources/sprache/Nederlands.properties rename to src/main/resources/language/Nederlands.properties diff --git a/src/main/resources/sprache/Norsk.properties b/src/main/resources/language/Norsk.properties similarity index 100% rename from src/main/resources/sprache/Norsk.properties rename to src/main/resources/language/Norsk.properties diff --git a/src/main/resources/sprache/Persian.properties b/src/main/resources/language/Persian.properties similarity index 100% rename from src/main/resources/sprache/Persian.properties rename to src/main/resources/language/Persian.properties diff --git a/src/main/resources/sprache/Polish.properties b/src/main/resources/language/Polish.properties similarity index 100% rename from src/main/resources/sprache/Polish.properties rename to src/main/resources/language/Polish.properties diff --git a/src/main/resources/sprache/Portugues.properties b/src/main/resources/language/Portugues.properties similarity index 100% rename from src/main/resources/sprache/Portugues.properties rename to src/main/resources/language/Portugues.properties diff --git a/src/main/resources/sprache/PortuguesBrasil.properties b/src/main/resources/language/PortuguesBrasil.properties similarity index 100% rename from src/main/resources/sprache/PortuguesBrasil.properties rename to src/main/resources/language/PortuguesBrasil.properties diff --git a/src/main/resources/sprache/Romanian.properties b/src/main/resources/language/Romanian.properties similarity index 100% rename from src/main/resources/sprache/Romanian.properties rename to src/main/resources/language/Romanian.properties diff --git a/src/main/resources/sprache/Russian.properties b/src/main/resources/language/Russian.properties similarity index 100% rename from src/main/resources/sprache/Russian.properties rename to src/main/resources/language/Russian.properties diff --git a/src/main/resources/sprache/Serbian(Cyrillic).properties b/src/main/resources/language/Serbian(Cyrillic).properties similarity index 100% rename from src/main/resources/sprache/Serbian(Cyrillic).properties rename to src/main/resources/language/Serbian(Cyrillic).properties diff --git a/src/main/resources/sprache/Slovak.properties b/src/main/resources/language/Slovak.properties similarity index 100% rename from src/main/resources/sprache/Slovak.properties rename to src/main/resources/language/Slovak.properties diff --git a/src/main/resources/sprache/Slovenian.properties b/src/main/resources/language/Slovenian.properties similarity index 100% rename from src/main/resources/sprache/Slovenian.properties rename to src/main/resources/language/Slovenian.properties diff --git a/src/main/resources/sprache/Spanish(AR).properties b/src/main/resources/language/Spanish(AR).properties similarity index 100% rename from src/main/resources/sprache/Spanish(AR).properties rename to src/main/resources/language/Spanish(AR).properties diff --git a/src/main/resources/sprache/Spanish.properties b/src/main/resources/language/Spanish.properties similarity index 100% rename from src/main/resources/sprache/Spanish.properties rename to src/main/resources/language/Spanish.properties diff --git a/src/main/resources/sprache/Svenska.properties b/src/main/resources/language/Svenska.properties similarity index 100% rename from src/main/resources/sprache/Svenska.properties rename to src/main/resources/language/Svenska.properties diff --git a/src/main/resources/sprache/Turkish.properties b/src/main/resources/language/Turkish.properties similarity index 100% rename from src/main/resources/sprache/Turkish.properties rename to src/main/resources/language/Turkish.properties diff --git a/src/main/resources/sprache/Ukranian.properties b/src/main/resources/language/Ukranian.properties similarity index 100% rename from src/main/resources/sprache/Ukranian.properties rename to src/main/resources/language/Ukranian.properties diff --git a/src/main/resources/sprache/Vlaams.properties b/src/main/resources/language/Vlaams.properties similarity index 100% rename from src/main/resources/sprache/Vlaams.properties rename to src/main/resources/language/Vlaams.properties diff --git a/src/test/java/core/constants/player/PlayerAbilityTest.kt b/src/test/java/core/constants/player/PlayerAbilityTest.kt index c768857d7..54139ed67 100644 --- a/src/test/java/core/constants/player/PlayerAbilityTest.kt +++ b/src/test/java/core/constants/player/PlayerAbilityTest.kt @@ -16,7 +16,7 @@ class PlayerAbilityTest { .hrfId(42) .build() hoAdmin.model = hoModel - hoAdmin.setLanguageBundle(null) + hoAdmin.clearTranslator(); } @Test diff --git a/src/test/java/core/playeravatars/PlayerAvatars.java b/src/test/java/core/playeravatars/PlayerAvatars.java index 9ddd004f2..bf6d041d7 100644 --- a/src/test/java/core/playeravatars/PlayerAvatars.java +++ b/src/test/java/core/playeravatars/PlayerAvatars.java @@ -2,10 +2,8 @@ import core.HO; import core.db.DBManager; -import core.db.user.UserManager; -import core.file.xml.XMLArenaParser; -import core.file.xml.XMLAvatarsParser; import core.model.HOVerwaltung; +import core.model.Translator; import core.net.MyConnector; import javax.imageio.ImageIO; @@ -13,11 +11,9 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Map; public class PlayerAvatars { @@ -26,7 +22,7 @@ public static void main(String[] args) throws IOException { HO.setPortable_version(true); DBManager.instance().loadUserParameter(); HOVerwaltung.instance().loadLatestHoModel(); - HOVerwaltung.instance().setResource("English"); + HOVerwaltung.instance().setTranslator(Translator.LANGUAGE_DEFAULT); // HOVerwaltung.instance().set final MyConnector mc = MyConnector.instance(); diff --git a/src/test/java/core/training/TrainingManagerTest.java b/src/test/java/core/training/TrainingManagerTest.java index 679a6f588..33e17c9f5 100644 --- a/src/test/java/core/training/TrainingManagerTest.java +++ b/src/test/java/core/training/TrainingManagerTest.java @@ -2,6 +2,8 @@ import core.HO; import core.model.HOVerwaltung; +import core.model.Translator; + import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -11,7 +13,7 @@ public static void main(String[] args) { HO.setPortable_version(true); HOVerwaltung.instance().loadLatestHoModel(); - HOVerwaltung.instance().setResource("English"); + HOVerwaltung.instance().setTranslator(Translator.LANGUAGE_DEFAULT); Instant endDate = Instant.now(); Instant startDate = endDate.minus(7, ChronoUnit.DAYS); diff --git a/src/test/java/core/util/HODateTimeTest.java b/src/test/java/core/util/HODateTimeTest.java index 545e88988..3c4e43b6e 100644 --- a/src/test/java/core/util/HODateTimeTest.java +++ b/src/test/java/core/util/HODateTimeTest.java @@ -2,7 +2,7 @@ import core.HO; import core.model.HOVerwaltung; -import core.model.misc.Basics; +import core.model.Translator; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -14,7 +14,7 @@ public void test() { HO.setPortable_version(true); HOVerwaltung.instance().loadLatestHoModel(); - HOVerwaltung.instance().setResource("English"); + HOVerwaltung.instance().setTranslator(Translator.LANGUAGE_DEFAULT); var nextTraining = HODateTime.fromHT("2022-03-31 08:30:00"); var localDateTime = nextTraining.toLocaleDateTime();