Merge pull request #2844 from federicobond/fix-osx-localization

Fix localization in OS X
This commit is contained in:
Ben Fry
2014-09-10 09:48:31 -04:00
5 changed files with 46 additions and 2 deletions
+2
View File
@@ -87,6 +87,7 @@ public class Language {
static private String[] listSupported() {
// List of languages in alphabetical order. (Add yours here.)
// Also remember to add it to the corresponding build/build.xml rule.
final String[] SUPPORTED = {
"de", // German, Deutsch
"en", // English
@@ -147,6 +148,7 @@ public class Language {
} catch (Exception e) {
e.printStackTrace();
}
Base.getPlatform().saveLanguage(language);
}
+2 -1
View File
@@ -74,6 +74,7 @@ public class Platform {
}
}
public void saveLanguage(String languageCode) {}
public void init(Base base) {
this.base = base;
@@ -216,4 +217,4 @@ public class Platform {
null);
}
*/
}
}
@@ -24,6 +24,7 @@ package processing.app.platform;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.apple.eio.FileManager;
@@ -47,6 +48,18 @@ public class MacPlatform extends Platform {
}
*/
public void saveLanguage(String language) {
String[] cmdarray = new String[]{
"defaults", "write",
System.getProperty("user.home") + "/Library/Preferences/org.processing.app",
"AppleLanguages", "-array", language
};
try {
Runtime.getRuntime().exec(cmdarray);
} catch (IOException e) {
Base.log("Error saving platform language: " + e.getMessage());
}
}
public void init(Base base) {
super.init(base);
@@ -205,4 +218,4 @@ public class MacPlatform extends Platform {
protected String getDocumentsFolder() throws FileNotFoundException {
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
}
}
}
+2
View File
@@ -496,6 +496,8 @@
value="macosx/work/Processing.app/Contents/Java" />
</antcall>
<exec executable="macosx/language_gen.py" />
<property name="launch4j.dir" value="macosx/work/Processing.app/Contents/Java/modes/java/application/launch4j" />
<!-- rename the version we need -->
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/python
import os, re
BASEDIR = os.path.dirname(os.path.realpath(__file__))
def supported_languages():
path = "../../app/src/processing/app/languages/languages.txt"
with open(os.path.join(BASEDIR, path)) as f:
lines = f.read().splitlines()
lines = filter(lambda l: re.match(r'^[a-z]{2}', l), lines)
lines = map(lambda l: re.sub(r'#.*', '', l).strip(), lines)
return lines
def lproj_directory(lang):
path = "work/Processing.app/Contents/Resources/{}.lproj".format(lang)
return os.path.join(BASEDIR, path)
if __name__ == "__main__":
for lang in supported_languages():
try:
os.mkdir(lproj_directory(lang))
except OSError:
pass