language selector functionality added

This commit is contained in:
gsanta 2014-04-21 19:46:38 +02:00 committed by Anton Keks
parent 61a974339e
commit af183d129f
4 changed files with 48 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# Messages in properties format
# To translate, copy this file to e.g. messages_fr.txt, where "fr" is the language code
preferences.language=Language
language.english=English
language.inherited=Inherited
language.hungarian=Hungarian
preferences.csv=CSV
preferences.csv.separator=CSV separator
menu.scan.save=&Save to file

View File

@ -52,11 +52,21 @@ public class Main {
Display.setAppName(Version.NAME);
Display display = Display.getDefault();
LOG.finer("SWT initialized after " + (System.currentTimeMillis() - startTime));
Locale locale = System.getProperty("locale") == null ? Locale.getDefault() : new Locale(System.getProperty("locale"));
Config globalConfig = Config.getConfig();
Locale locale;
ScannerConfig scannerConfig = globalConfig.forScanner();
if( scannerConfig.language.equals("language.inherited")) {
locale = System.getProperty("locale") == null ? Locale.getDefault() : new Locale(System.getProperty("locale"));
} else if(scannerConfig.language.equals("language.hungarian")) {
locale = new Locale("hu", "HU");
} else {
locale = Locale.US;
}
Labels.initialize(locale);
Config globalConfig = Config.getConfig();
LOG.finer("Labels and Config initialized after " + (System.currentTimeMillis() - startTime));
ComponentRegistry componentRegistry = new ComponentRegistry();

View File

@ -30,6 +30,7 @@ public class ScannerConfig {
public boolean useRequestedPorts;
public String notAvailableText;
public String notScannedText;
public String language;
/**
* Package local constructor.
@ -53,6 +54,7 @@ public class ScannerConfig {
useRequestedPorts = preferences.getBoolean("useRequestedPorts", true);
notAvailableText = preferences.get("notAvailableText", Labels.getLabel("fetcher.value.notAvailable"));
notScannedText = preferences.get("notScannedText", Labels.getLabel("fetcher.value.notScanned"));
language = preferences.get("language", "language.english");
}
/**
@ -73,5 +75,6 @@ public class ScannerConfig {
preferences.putBoolean("useRequestedPorts", useRequestedPorts);
preferences.put("notAvailableText", notAvailableText);
preferences.put("notScannedText", notScannedText);
preferences.put("language", language);
}
}

View File

@ -63,6 +63,8 @@ public class PreferencesDialog extends AbstractModalDialog {
private Button[] displayMethod;
private Button showInfoCheckbox;
private Button askConfirmationCheckbox;
private Combo languageCombo;
private String[] languageNames = { "language.inherited", "language.english", "language.hungarian" };
public PreferencesDialog(PingerRegistry pingerRegistry, ScannerConfig scannerConfig, GUIConfig guiConfig, ConfigDetectorDialog configDetectorDialog) {
this.pingerRegistry = pingerRegistry;
@ -287,6 +289,26 @@ public class PreferencesDialog extends AbstractModalDialog {
askConfirmationCheckbox.setText(Labels.getLabel("preferences.display.confirmation.newScan"));
showInfoCheckbox = new Button(showStatsGroup, SWT.CHECK);
showInfoCheckbox.setText(Labels.getLabel("preferences.display.confirmation.showInfo"));
groupLayout = new GridLayout();
groupLayout.numColumns = 2;
gridData = new GridData(80, SWT.DEFAULT);
Group languageGroup = new Group(displayTab, SWT.NONE);
languageGroup.setLayout(groupLayout);
languageGroup.setText(Labels.getLabel("preferences.language"));
label = new Label(languageGroup, SWT.NONE);
label.setText(Labels.getLabel("preferences.language"));
languageCombo = new Combo(languageGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
languageCombo.setLayoutData(gridData);
for (int i = 0; i < languageNames.length; i++) {
languageCombo.add(Labels.getLabel(languageNames[i]));
// this is used by savePreferences()
languageCombo.setData(Integer.toString(i), languageNames[i]);
}
languageCombo.select(0);
}
/**
@ -397,6 +419,11 @@ public class PreferencesDialog extends AbstractModalDialog {
displayMethod[guiConfig.displayMethod.ordinal()].setSelection(true);
showInfoCheckbox.setSelection(guiConfig.showScanStats);
askConfirmationCheckbox.setSelection(guiConfig.askScanConfirmation);
for (int i = 0; i < languageNames.length; i++) {
if (scannerConfig.language.equals(languageNames[i])) {
languageCombo.select(i);
}
}
}
private void savePreferences() {
@ -436,6 +463,7 @@ public class PreferencesDialog extends AbstractModalDialog {
}
guiConfig.showScanStats = showInfoCheckbox.getSelection();
guiConfig.askScanConfirmation = askConfirmationCheckbox.getSelection();
scannerConfig.language = (String) languageCombo.getData(Integer.toString(languageCombo.getSelectionIndex()));
}
/**