Skip to content

Commit

Permalink
sort the language options by their code
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Nov 25, 2022
1 parent d69e14f commit f33f7ad
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions app/src/processing/app/ui/PreferencesFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@
import javax.swing.border.*;

import com.formdev.flatlaf.FlatClientProperties;

import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.SketchName;
import processing.awt.ShimAWT;
import processing.core.*;

import processing.core.PApplet;
import processing.data.StringList;


/**
Expand Down Expand Up @@ -160,20 +163,29 @@ public PreferencesFrame(Base base) {

Map<String, String> languages = Language.getLanguages();
String[] languageSelection = new String[languages.size()];
StringList codeList = new StringList(languages.keySet());

// Build a map from the display names of the languages to their codes
for (String code : codeList) {
languageToCode.put(languages.get(code), code);
}

// Set the current language as the first/default choice
languageSelection[0] = languages.get(Language.getLanguage());
String currentCode = Language.getLanguage();
languageSelection[0] = languages.get(currentCode);

// Remove that language from the list of other possible choices
codeList.removeValue(currentCode);
// Sort the language list based on its code; this avoids showing preference
// to any language, and keeps related variants together (zh_CN and zh_TW).
codeList.sort();

// Start counting from 1 to fill out the rest of the list
int i = 1;
for (Map.Entry<String, String> lang : languages.entrySet()) {
languageToCode.put(lang.getValue(), lang.getKey());
if (!lang.getKey().equals(Language.getLanguage())) {
languageSelection[i++] = lang.getValue();
}
for (String code : codeList) {
languageSelection[i++] = languages.get(code);
}
languageSelectionBox.setModel(new DefaultComboBoxModel<>(languageSelection));
// languageRestartLabel = new JLabel(Language.text("preferences.requires_restart"));
// languageRestartLabel.setVisible(false);
//languageSelectionBox.addItemListener(e -> languageRestartLabel.setVisible(languageSelectionBox.getSelectedIndex() != 0));
languageSelectionBox.addItemListener(e -> updateRestart("language", languageSelectionBox.getSelectedIndex() != 0));
languageSelectionBox.setRenderer(new LanguageRenderer());

Expand Down

0 comments on commit f33f7ad

Please sign in to comment.