Skip to content

Commit a717ff2

Browse files
committed
Merge pull request arduino#71 from dcuartielles/master
added improved multilanguage functionality
2 parents d059459 + e2c690b commit a717ff2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+59969
-1279
lines changed

app/src/processing/app/11418.po

+1,481
Large diffs are not rendered by default.

app/src/processing/app/11418.properties

Whitespace-only changes.

app/src/processing/app/Base.java

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ static public void main(String args[]) {
169169
// run static initialization that grabs all the prefs
170170
Preferences.init(null);
171171

172+
// load the I18n module for internationalization
173+
I18n.init(Preferences.get("editor.languages.current"));
174+
172175
// setup the theme coloring fun
173176
Theme.init();
174177

app/src/processing/app/I18n.java

+13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@
1212
*/
1313

1414
package processing.app;
15+
1516
import java.util.*;
17+
import java.util.Locale.*;
1618
import java.text.MessageFormat;
1719

1820
public class I18n {
21+
// start using current locale but still allow using the dropdown list later
1922
private static ResourceBundle i18n = ResourceBundle.getBundle("processing.app.Resources");
23+
public static Locale locale;
24+
25+
static protected void init (String language) {
26+
// there might be a null pointer exception ... most likely will never happen but the jvm gets mad
27+
try {
28+
locale = new Locale(language);
29+
i18n = ResourceBundle.getBundle("processing.app.Resources", locale);
30+
} catch (java.lang.NullPointerException e) {
31+
}
32+
}
2033

2134
public static String _(String s) {
2235
try {

app/src/processing/app/Preferences.java

+105
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,81 @@ public class Preferences {
7979
static final String PROMPT_OK = _("OK");
8080
static final String PROMPT_BROWSE = _("Browse");
8181

82+
// XXX: DC 20120407
83+
// Language Combo Box
84+
// the right way to do this would be having a string[] inside the preferences.txt
85+
// file like follows:
86+
//
87+
// # list of available languages (in English so far)
88+
// editor.languages.available.list = Catalan,English,Spanish
89+
//
90+
// # list of ISO names (same order as previous)
91+
// editor.languages.ISO.list = ca,en,es
92+
//
93+
// --> but that will require having a method to upgrade to the latest selection of
94+
// translation files. That could be done in multiple ways, but requires some thought
95+
//
96+
// the code to gather those arrays into Preferences.java goes as follows:
97+
//
98+
// String languagesAvailable = Preferences.get("editor.languages.available.list");
99+
// String languagesAvailableISO = Preferences.get("editor.languages.ISO.list");
100+
// String[] languages = languagesAvailable.split(",");
101+
// String[] languagesISO = languagesAvailableISO.split(",");
102+
//
103+
// --> instead, DM and DC agree that, for the time being, the languages will be listed internally
104+
// inside the Java code, they will have to be moved out at some point
105+
//
106+
// also note that right now, by default we will take English, in the future, once JRE7 is running in
107+
// Arduino, we will use the locale, since it will behave in a similar way for all OSs. Thing is, up
108+
// to JRE6, it was misbehaving as noted here:
109+
// http://stackoverflow.com/questions/7107972/java-7-default-locale
110+
//
111+
// ALSO: for this to work, the languages/languagesISO arraylists need to be declared global, yeah!
112+
113+
// language related arrays, please read notes later, where the language combo box is introduced
114+
String[] languages = {
115+
_("Catalan"),
116+
_("Chinese Simplified"),
117+
_("Chinese Taiwan"),
118+
_("Danish"),
119+
_("Dutch"),
120+
_("English"),
121+
_("French"),
122+
_("Filipino"),
123+
_("Galician"),
124+
_("German"),
125+
_("Greek"),
126+
_("Hungarian"),
127+
_("Italian"),
128+
_("Japanese"),
129+
_("Latvian"),
130+
_("Persian"),
131+
_("Portuguese (Brazil)"),
132+
_("Romanian"),
133+
_("Russian"),
134+
_("Spanish")};
135+
String[] languagesISO = {
136+
"ca",
137+
"zh_cn",
138+
"zh_tw",
139+
"da",
140+
"nl",
141+
"en",
142+
"fr",
143+
"tl",
144+
"gl",
145+
"de",
146+
"el",
147+
"hu",
148+
"it",
149+
"ja",
150+
"lv",
151+
"fa",
152+
"pt_br",
153+
"ro",
154+
"ru",
155+
"es"};
156+
82157
/**
83158
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
84159
* Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper.
@@ -124,6 +199,7 @@ public class Preferences {
124199
JTextField fontSizeField;
125200
JCheckBox updateExtensionBox;
126201
JCheckBox autoAssociateBox;
202+
JComboBox comboLanguage;
127203

128204

129205
// the calling editor, so updates can be applied
@@ -350,6 +426,30 @@ public void actionPerformed(ActionEvent e) {
350426
top += d.height + GUI_BETWEEN;
351427
}
352428

429+
//Label for the language combo box
430+
box = Box.createHorizontalBox();
431+
label = new JLabel(_("Preferred Language: "));
432+
box.add(label);
433+
434+
//Create the combo box, select the item at index 4.
435+
comboLanguage = new JComboBox(languages);
436+
comboLanguage.setSelectedIndex((Arrays.asList(languagesISO)).indexOf(Preferences.get("editor.languages.current")));
437+
comboLanguage.addActionListener(new ActionListener() {
438+
public void actionPerformed(ActionEvent evt) {
439+
JComboBox cb = (JComboBox)evt.getSource();
440+
// the update to the language is done outside
441+
}
442+
});
443+
box.add(comboLanguage);
444+
label = new JLabel(_(" (requires restart of Arduino)"));
445+
box.add(label);
446+
pain.add(box);
447+
d = box.getPreferredSize();
448+
box.setForeground(Color.gray);
449+
box.setBounds(left, top, d.width, d.height);
450+
right = Math.max(right, left + d.width);
451+
top += d.height + GUI_BETWEEN;
452+
353453

354454
// More preferences are in the ...
355455

@@ -539,6 +639,11 @@ protected void applyFrame() {
539639

540640
setBoolean("editor.update_extension", updateExtensionBox.isSelected());
541641

642+
// adds the selected language to the preferences file
643+
Object newItem = comboLanguage.getSelectedItem();
644+
int pos = (Arrays.asList(languages)).indexOf(newItem.toString()); // position in the languages array
645+
set("editor.languages.current",(Arrays.asList(languagesISO)).get(pos));
646+
542647
editor.applyPreferences();
543648
}
544649

0 commit comments

Comments
 (0)