From 0ac0e46f2f8fc7c078597e75ab54380a0f80fa84 Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Thu, 27 Dec 2018 13:10:39 +0200 Subject: [PATCH] make Brazilian Portuguese translation actually work --- RELEASE-NOTES | 3 +- resources/messages.properties | 1 + resources/messages_pt_BR.properties | 12 -- src/net/azib/ipscan/config/Config.java | 220 ++++++++++---------- src/net/azib/ipscan/config/Labels.java | 2 +- test/net/azib/ipscan/config/ConfigTest.java | 55 +++-- 6 files changed, 150 insertions(+), 143 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 640f61df0..6bffb8731 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -1,8 +1,9 @@ Changes in 3.5.4: -- Translation updates +- Translation updates, added Brazilian Portuguese - Small bugfixes - Mac vendor updates - JDK 11 support in Windows exe +- Linux version will now use GTK 3 by default, enabling touch screen support - New build system using gradle and proguard - This is the last release to support running under Java 7 diff --git a/resources/messages.properties b/resources/messages.properties index d6f0dfd1c..8f1091bcd 100644 --- a/resources/messages.properties +++ b/resources/messages.properties @@ -19,6 +19,7 @@ language.ku=کوردی language.lt=Lietuvių language.tr=Türkçe language.gr=Ελληνικά +language.pt_BR=Português (BR) preferences.csv=CSV preferences.csv.separator=CSV separator text.progress.ipProgressBar=IP status: diff --git a/resources/messages_pt_BR.properties b/resources/messages_pt_BR.properties index e7680173c..43d4b5f14 100644 --- a/resources/messages_pt_BR.properties +++ b/resources/messages_pt_BR.properties @@ -5,18 +5,6 @@ preferences.language=Idioma preferences.language.needsRestart=Você precisa reiniciar o aplicativo para que a alteração do idioma entre em vigor preferences.language.someIncomplete=Algumas traduções estão incompletas language.system=Padrão do Sistema -language.en=English -language.ru=Русский -language.de=Deutsch -language.es=Español -language.fr=French -language.hu=Magyar -language.it=Italiano -language.ku=کوردی -language.lt=Lietuvių -language.tr=Türkçe -language.gr=Ελληνικά -language.pt_BR=Português Brasil preferences.csv=CSV preferences.csv.separator=Separador CSV text.progress.ipProgressBar=Status IP: diff --git a/src/net/azib/ipscan/config/Config.java b/src/net/azib/ipscan/config/Config.java index 40af9ac21..796193943 100644 --- a/src/net/azib/ipscan/config/Config.java +++ b/src/net/azib/ipscan/config/Config.java @@ -1,108 +1,112 @@ -package net.azib.ipscan.config; - -import java.util.Locale; -import java.util.UUID; -import java.util.prefs.Preferences; - -/** - * This class encapsulates preferences of the program. - * It is a singleton class. - * - * @author Anton Keks - */ -public final class Config { - - /** Singleton instance */ - private static Config globalConfig; - - private Preferences preferences; - public String language; - public String uuid; - - /** easily accessible scanner configuration */ - private ScannerConfig scannerConfig; - /** various GUI preferences and dimensions are stored here */ - private GUIConfig guiConfig; - /** favorites are stored here */ - private FavoritesConfig favoritesConfig; - /** openers are stored here */ - private OpenersConfig openersConfig; - - Config() { - preferences = Preferences.userRoot().node("ipscan"); - scannerConfig = new ScannerConfig(preferences); - guiConfig = new GUIConfig(preferences); - favoritesConfig = new FavoritesConfig(preferences); - openersConfig = new OpenersConfig(preferences); - language = preferences.get("language", "system"); - uuid = preferences.get("uuid", null); - if (uuid == null) { - uuid = UUID.randomUUID().toString(); - preferences.put("uuid", uuid); - } - } - - /** - * Initializes the singleton instance - */ - public static Config getConfig() { - if (globalConfig == null) { - globalConfig = new Config(); - } - return globalConfig; - } - - public void store() { - preferences.put("language", language); - preferences.put("uuid", uuid); - scannerConfig.store(); - guiConfig.store(); - favoritesConfig.store(); - openersConfig.store(); - } - - public Preferences getPreferences() { - return preferences; - } - - /** - * @return ScannerConfig instance (quick access) - */ - public ScannerConfig forScanner() { - return scannerConfig; - } - - /** - * @return Favorites config (only local access) - */ - FavoritesConfig forFavorites() { - return favoritesConfig; - } - - /** - * @return Openers config (only local access); - */ - public OpenersConfig forOpeners() { - return openersConfig; - } - - /** - * @return Dimensions config (quick access); - */ - public GUIConfig forGUI() { - return guiConfig; - } - - public Locale getLocale() { - if (language == null || "system".equals(language)) { - return System.getProperty("locale") == null ? Locale.getDefault() : new Locale(System.getProperty("locale")); - } - else { - return new Locale(language); - } - } - - public String getUUID() { - return uuid; - } -} +package net.azib.ipscan.config; + +import java.util.Locale; +import java.util.UUID; +import java.util.prefs.Preferences; + +/** + * This class encapsulates preferences of the program. + * It is a singleton class. + * + * @author Anton Keks + */ +public final class Config { + + /** Singleton instance */ + private static Config globalConfig; + + private Preferences preferences; + public String language; + public String uuid; + + /** easily accessible scanner configuration */ + private ScannerConfig scannerConfig; + /** various GUI preferences and dimensions are stored here */ + private GUIConfig guiConfig; + /** favorites are stored here */ + private FavoritesConfig favoritesConfig; + /** openers are stored here */ + private OpenersConfig openersConfig; + + Config() { + preferences = Preferences.userRoot().node("ipscan"); + scannerConfig = new ScannerConfig(preferences); + guiConfig = new GUIConfig(preferences); + favoritesConfig = new FavoritesConfig(preferences); + openersConfig = new OpenersConfig(preferences); + language = preferences.get("language", "system"); + uuid = preferences.get("uuid", null); + if (uuid == null) { + uuid = UUID.randomUUID().toString(); + preferences.put("uuid", uuid); + } + } + + /** + * Initializes the singleton instance + */ + public static Config getConfig() { + if (globalConfig == null) { + globalConfig = new Config(); + } + return globalConfig; + } + + public void store() { + preferences.put("language", language); + preferences.put("uuid", uuid); + scannerConfig.store(); + guiConfig.store(); + favoritesConfig.store(); + openersConfig.store(); + } + + public Preferences getPreferences() { + return preferences; + } + + /** + * @return ScannerConfig instance (quick access) + */ + public ScannerConfig forScanner() { + return scannerConfig; + } + + /** + * @return Favorites config (only local access) + */ + FavoritesConfig forFavorites() { + return favoritesConfig; + } + + /** + * @return Openers config (only local access); + */ + public OpenersConfig forOpeners() { + return openersConfig; + } + + /** + * @return Dimensions config (quick access); + */ + public GUIConfig forGUI() { + return guiConfig; + } + + public Locale getLocale() { + if (language == null || "system".equals(language)) { + return System.getProperty("locale") == null ? Locale.getDefault() : createLocale(System.getProperty("locale")); + } + else { + return createLocale(language); + } + } + + private Locale createLocale(String locale) { + return Locale.forLanguageTag(locale.replace('_', '-')); + } + + public String getUUID() { + return uuid; + } +} diff --git a/src/net/azib/ipscan/config/Labels.java b/src/net/azib/ipscan/config/Labels.java index 67958a756..68c5df25d 100644 --- a/src/net/azib/ipscan/config/Labels.java +++ b/src/net/azib/ipscan/config/Labels.java @@ -24,7 +24,7 @@ * @author Anton Keks */ public final class Labels { - public static final String[] LANGUAGES = { "system", "en", "ru", "de", "hu", "lt", "es", "fr", "it", "ku", "tr", "gr"}; + public static final String[] LANGUAGES = { "system", "en", "ru", "de", "hu", "lt", "es", "fr", "it", "ku", "tr", "gr", "pt_BR"}; private static final Logger LOG = Logger.getLogger(Labels.class.getName()); private static Labels instance; diff --git a/test/net/azib/ipscan/config/ConfigTest.java b/test/net/azib/ipscan/config/ConfigTest.java index 8a6b0adc3..ea74b56b2 100644 --- a/test/net/azib/ipscan/config/ConfigTest.java +++ b/test/net/azib/ipscan/config/ConfigTest.java @@ -1,21 +1,34 @@ -package net.azib.ipscan.config; - -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -/** - * @author Anton Keks - */ -public class ConfigTest { - - @Test - public void testGetters() { - Config config = Config.getConfig(); - assertNotNull(config.getPreferences()); - assertNotNull(config.forScanner()); - assertNotNull(config.forGUI()); - assertNotNull(config.forFavorites()); - assertNotNull(config.forOpeners()); - } -} +package net.azib.ipscan.config; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * @author Anton Keks + */ +public class ConfigTest { + Config config = Config.getConfig(); + + @Test + public void locale() { + config.language = "et"; + assertEquals(config.getLocale().toString(), "et"); + } + + @Test + public void localeWithRegion() { + config.language = "pt_BR"; + assertEquals(config.getLocale().toString(), "pt_BR"); + } + + @Test + public void testGetters() { + assertNotNull(config.getPreferences()); + assertNotNull(config.forScanner()); + assertNotNull(config.forGUI()); + assertNotNull(config.forFavorites()); + assertNotNull(config.forOpeners()); + } +}