Skip to content

Commit 7500776

Browse files
committed
Fix localization in OS X
1 parent b489a1a commit 7500776

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

app/src/processing/app/Language.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private Language() {
8787

8888
static private String[] listSupported() {
8989
// List of languages in alphabetical order. (Add yours here.)
90+
// Also remember to add it to the corresponding build/build.xml rule.
9091
final String[] SUPPORTED = {
9192
"de", // German, Deutsch
9293
"en", // English
@@ -147,6 +148,7 @@ static public void saveLanguage(String language) {
147148
} catch (Exception e) {
148149
e.printStackTrace();
149150
}
151+
Base.getPlatform().saveLanguage(language);
150152
}
151153

152154

app/src/processing/app/Platform.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void setLookAndFeel() throws Exception {
7474
}
7575
}
7676

77+
public void saveLanguage(String languageCode) {}
7778

7879
public void init(Base base) {
7980
this.base = base;
@@ -216,4 +217,4 @@ protected void showLauncherWarning() {
216217
null);
217218
}
218219
*/
219-
}
220+
}

app/src/processing/app/platform/MacPlatform.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.File;
2626
import java.io.FileNotFoundException;
27+
import java.io.IOException;
2728

2829
import com.apple.eio.FileManager;
2930

@@ -47,6 +48,18 @@ public void setLookAndFeel() throws Exception {
4748
}
4849
*/
4950

51+
public void saveLanguage(String language) {
52+
String[] cmdarray = new String[]{
53+
"defaults", "write",
54+
System.getProperty("user.home") + "/Library/Preferences/org.processing.app",
55+
"AppleLanguages", "-array", language
56+
};
57+
try {
58+
Runtime.getRuntime().exec(cmdarray);
59+
} catch (IOException e) {
60+
Base.log("Error saving platform language: " + e.getMessage());
61+
}
62+
}
5063

5164
public void init(Base base) {
5265
super.init(base);
@@ -205,4 +218,4 @@ protected String getLibraryFolder() throws FileNotFoundException {
205218
protected String getDocumentsFolder() throws FileNotFoundException {
206219
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
207220
}
208-
}
221+
}

build/build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@
496496
value="macosx/work/Processing.app/Contents/Java" />
497497
</antcall>
498498

499+
<exec executable="macosx/language_gen.py" />
500+
499501
<property name="launch4j.dir" value="macosx/work/Processing.app/Contents/Java/modes/java/application/launch4j" />
500502

501503
<!-- rename the version we need -->

build/macosx/language_gen.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python
2+
3+
import os, re
4+
5+
BASEDIR = os.path.dirname(os.path.realpath(__file__))
6+
7+
def supported_languages():
8+
path = "../../app/src/processing/app/languages/languages.txt"
9+
with open(os.path.join(BASEDIR, path)) as f:
10+
lines = f.read().splitlines()
11+
12+
lines = filter(lambda l: re.match(r'^[a-z]{2}', l), lines)
13+
lines = map(lambda l: re.sub(r'#.*', '', l).strip(), lines)
14+
return lines
15+
16+
def lproj_directory(lang):
17+
path = "work/Processing.app/Contents/Resources/{}.lproj".format(lang)
18+
return os.path.join(BASEDIR, path)
19+
20+
21+
if __name__ == "__main__":
22+
for lang in supported_languages():
23+
try:
24+
os.mkdir(lproj_directory(lang))
25+
except OSError:
26+
pass

0 commit comments

Comments
 (0)