Skip to content

Commit 4d8d229

Browse files
BananeweizenCalixte
authored andcommitted
Issue #506: Available languages must be hard-coded
Don't have the language list in the properties, but rather in code. Also add a localized version of the language name to the dropdown list.
1 parent 57fc519 commit 4d8d229

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/Messages.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ public final class Messages extends NLS {
176176

177177
public static String CheckstylePreferencePage_lblLocaleLanguage;
178178

179-
public static String CheckstylePreferencePage_lblLocaleLanguages;
180-
181179
public static String CheckstylePreferencePage_version;
182180

183181
public static String CheckstylePropertyPage_btnActivateCheckstyle;

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/messages.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ CheckstylePreferencePage_lblIncludeModuleIds=Include module id (if available) in
6262
CheckstylePreferencePage_lblIncludeRulenames = Include rule names in violation messages
6363
CheckstylePreferencePage_lblLimitMarker = Limit Checkstyle markers per resource to
6464
CheckstylePreferencePage_lblLocaleLanguage= Rule message language
65-
CheckstylePreferencePage_lblLocaleLanguages= default,de,en,es,fi,fr,ja,pt,tr,zh
6665
CheckstylePreferencePage_lblProjectUsage = Used in projects:
6766
CheckstylePreferencePage_lblRebuild = Rebuild projects if needed:
6867
CheckstylePreferencePage_lblWarnFilesets = Warn before losing configured file sets

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
package net.sf.eclipsecs.ui.preferences;
2222

23+
import java.util.Arrays;
2324
import java.util.Collection;
25+
import java.util.List;
26+
import java.util.Locale;
27+
import java.util.stream.Collectors;
28+
import java.util.stream.Stream;
2429

2530
import org.eclipse.core.resources.IProject;
2631
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -79,6 +84,15 @@
7984
*/
8085
public class CheckstylePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
8186

87+
private static final String DEFAULT_LANGUAGE = "default";
88+
89+
private static final List<String> SUPPORTED_LANGUAGES = Stream.concat(
90+
Stream.of(DEFAULT_LANGUAGE),
91+
Arrays.stream("de,en,es,fi,fr,ja,pt,tr,zh"
92+
.split(","))
93+
.sorted())
94+
.collect(Collectors.toList());
95+
8296
private final PageController mController = new PageController();
8397

8498
private final ICheckConfigurationWorkingSet mWorkingSet;
@@ -201,9 +215,15 @@ private Composite createGeneralContents(Composite parent) {
201215
final Label lblLanguage = new Label(langComposite, SWT.NULL);
202216
lblLanguage.setText(Messages.CheckstylePreferencePage_lblLocaleLanguage);
203217
mLanguageIf = new Combo(langComposite, SWT.READ_ONLY);
204-
mLanguageIf.setItems(Messages.CheckstylePreferencePage_lblLocaleLanguages.split("[, ;]+"));
218+
mLanguageIf.setItems(SUPPORTED_LANGUAGES.stream().map(code -> {
219+
if (code == DEFAULT_LANGUAGE) {
220+
return code;
221+
}
222+
var loc = Locale.forLanguageTag(code);
223+
return code + " - " + loc.getDisplayLanguage(loc);
224+
}).toArray(String[]::new));
205225
final String lang = CheckstylePluginPrefs.getString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE);
206-
final int selectedLang = mLanguageIf.indexOf(lang == null || lang.isEmpty() ? "default" : lang);
226+
final int selectedLang = SUPPORTED_LANGUAGES.indexOf(lang == null || lang.isEmpty() ? DEFAULT_LANGUAGE : lang);
207227
if (selectedLang != -1) {
208228
mLanguageIf.select(selectedLang);
209229
}
@@ -376,7 +396,7 @@ public boolean performOk() {
376396
mWorkingSet.store();
377397

378398
CheckstylePluginPrefs.setString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE,
379-
mLanguageIf.getItem(mLanguageIf.getSelectionIndex()));
399+
SUPPORTED_LANGUAGES.get(mLanguageIf.getSelectionIndex()));
380400

381401
//
382402
// Save the general preferences.

0 commit comments

Comments
 (0)