Skip to content

Commit

Permalink
make Brazilian Portuguese translation actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Dec 27, 2018
1 parent a537d48 commit 0ac0e46
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 143 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions resources/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
220 changes: 112 additions & 108 deletions src/net/azib/ipscan/config/Config.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/net/azib/ipscan/config/Labels.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
55 changes: 34 additions & 21 deletions test/net/azib/ipscan/config/ConfigTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 0ac0e46

Please sign in to comment.