hacked the IDE to support multiple translations and include a dropdown list to choose the most convenient

This commit is contained in:
David Cuartielles 2012-04-08 03:51:37 +02:00
parent ad1d5ca89d
commit c3535a0d8e
50 changed files with 57471 additions and 1436 deletions

File diff suppressed because it is too large Load Diff

View File

View File

@ -169,6 +169,9 @@ public class Base {
// run static initialization that grabs all the prefs
Preferences.init(null);
// load the I18n module for internationalization
I18n.init(Preferences.get("editor.languages.current"));
// setup the theme coloring fun
Theme.init();

View File

@ -12,11 +12,24 @@
*/
package processing.app;
import java.util.*;
import java.util.Locale.*;
import java.text.MessageFormat;
public class I18n {
// start using current locale but still allow using the dropdown list later
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
public static Locale locale;
static protected void init (String language) {
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
try {
locale = new Locale(language);
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
} catch (java.lang.NullPointerException e) {
}
}
public static String _(String s) {
try {

View File

@ -79,6 +79,79 @@ public class Preferences {
static final String PROMPT_OK = _("OK");
static final String PROMPT_BROWSE = _("Browse");
// XXX: DC 20120407
// Language Combo Box
// the right way to do this would be having a string[] inside the preferences.txt
// file like follows:
//
// # list of available languages (in English so far)
// editor.languages.available.list = Catalan,English,Spanish
//
// # list of ISO names (same order as previous)
// editor.languages.ISO.list = ca,en,es
//
// --> but that will require having a method to upgrade to the latest selection of
// translation files. That could be done in multiple ways, but requires some thought
//
// the code to gather those arrays into Preferences.java goes as follows:
//
// String languagesAvailable = Preferences.get("editor.languages.available.list");
// String languagesAvailableISO = Preferences.get("editor.languages.ISO.list");
// String[] languages = languagesAvailable.split(",");
// String[] languagesISO = languagesAvailableISO.split(",");
//
// --> instead, DM and DC agree that, for the time being, the languages will be listed internally
// inside the Java code, they will have to be moved out at some point
//
// also note that right now, by default we will take English, in the future, once JRE7 is running in
// Arduino, we will use the locale, since it will behave in a similar way for all OSs. Thing is, up
// to JRE6, it was misbehaving as noted here:
// http://stackoverflow.com/questions/7107972/java-7-default-locale
//
// ALSO: for this to work, the languages/languagesISO arraylists need to be declared global, yeah!
// language related arrays, please read notes later, where the language combo box is introduced
String[] languages = {
_("Catalan"),
_("Chinese Simplified"),
_("Chinese Taiwan"),
_("Danish"),
_("Dutch"),
_("English"),
_("French"),
_("Filipino"),
_("Galician"),
_("German"),
_("Greek"),
_("Hungarian"),
_("Italian"),
_("Japanese"),
_("Latvian"),
_("Persian"),
_("Portuguese (Brazil)"),
_("Romanian"),
_("Spanish")};
String[] languagesISO = {
"ca",
"zh_cn",
"zh_tw",
"da",
"nl",
"en",
"fr",
"tl",
"gl",
"de",
"el",
"hu",
"it",
"ja",
"lv",
"fa",
"pt_br",
"ro",
"es"};
/**
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
* Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper.
@ -124,6 +197,7 @@ public class Preferences {
JTextField fontSizeField;
JCheckBox updateExtensionBox;
JCheckBox autoAssociateBox;
JComboBox comboLanguage;
// the calling editor, so updates can be applied
@ -350,6 +424,30 @@ public class Preferences {
top += d.height + GUI_BETWEEN;
}
//Label for the language combo box
box = Box.createHorizontalBox();
label = new JLabel(_("Preferred Language: "));
box.add(label);
//Create the combo box, select the item at index 4.
comboLanguage = new JComboBox(languages);
comboLanguage.setSelectedIndex((Arrays.asList(languagesISO)).indexOf(Preferences.get("editor.languages.current")));
comboLanguage.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JComboBox cb = (JComboBox)evt.getSource();
// the update to the language is done outside
}
});
box.add(comboLanguage);
label = new JLabel(_(" (requires restart of Arduino)"));
box.add(label);
pain.add(box);
d = box.getPreferredSize();
box.setForeground(Color.gray);
box.setBounds(left, top, d.width, d.height);
right = Math.max(right, left + d.width);
top += d.height + GUI_BETWEEN;
// More preferences are in the ...
@ -539,6 +637,11 @@ public class Preferences {
setBoolean("editor.update_extension", updateExtensionBox.isSelected());
// adds the selected language to the preferences file
Object newItem = comboLanguage.getSelectedItem();
int pos = (Arrays.asList(languages)).indexOf(newItem.toString()); // position in the languages array
set("editor.languages.current",(Arrays.asList(languagesISO)).get(pos));
editor.applyPreferences();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -255,3 +255,9 @@ serial.databits=8
serial.stopbits=1
serial.parity=N
serial.debug_rate=9600
# I18 Preferences
# default chosen language (none for none)
editor.languages.current = en