Skip to content

added improved multilanguage functionality #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,481 changes: 1,481 additions & 0 deletions app/src/processing/app/11418.po

Large diffs are not rendered by default.

Empty file.
3 changes: 3 additions & 0 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ static public void main(String args[]) {
// 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();

Expand Down
13 changes: 13 additions & 0 deletions app/src/processing/app/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
105 changes: 105 additions & 0 deletions app/src/processing/app/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,81 @@ 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"),
_("Russian"),
_("Spanish")};
String[] languagesISO = {
"ca",
"zh_cn",
"zh_tw",
"da",
"nl",
"en",
"fr",
"tl",
"gl",
"de",
"el",
"hu",
"it",
"ja",
"lv",
"fa",
"pt_br",
"ro",
"ru",
"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.
Expand Down Expand Up @@ -124,6 +199,7 @@ public class Preferences {
JTextField fontSizeField;
JCheckBox updateExtensionBox;
JCheckBox autoAssociateBox;
JComboBox comboLanguage;


// the calling editor, so updates can be applied
Expand Down Expand Up @@ -350,6 +426,30 @@ public void actionPerformed(ActionEvent e) {
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 ...

Expand Down Expand Up @@ -539,6 +639,11 @@ protected void applyFrame() {

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();
}

Expand Down
Loading