Skip to content
This repository has been archived by the owner on Oct 11, 2019. It is now read-only.

Commit

Permalink
fix macOS locale issues #47
Browse files Browse the repository at this point in the history
  • Loading branch information
cute committed Sep 22, 2016
1 parent 5a09bce commit 879227e
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions SketchI18N.sketchplugin/Contents/Sketch/app.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
var onRun = function(context) {
var manager,
languagePath,
doc = context.document,
command = context.command,
identifier = command.identifier(),
resourcesPath = command.pluginBundle().url().path(),
language = NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages").objectAtIndex(0),
language = NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages").objectAtIndex(0);

for(;;){
languagePath = resourcesPath + "/Contents/Resources/i18n/" + language + ".json";
if (NSFileManager.defaultManager().fileExistsAtPath(languagePath)) {
break;
}
else {
var index = language.lastIndexOf("-");
if (index == -1) {
return;
}
language = language.substring(0, index);
}
}

if (NSFileManager.defaultManager().fileExistsAtPath(languagePath)) {
if (!NSClassFromString("SketchI18NPluginManager")) {
var mocha = Mocha.sharedRuntime();
i18n = [NSString stringWithContentsOfFile: languagePath encoding: NSUTF8StringEncoding error: nil];
mocha.loadFrameworkWithName_inDirectory("SketchI18NPlugin", resourcesPath + "/Contents/Resources");
manager = SketchI18NPluginManager.manager();
var i18n = NSString.stringWithContentsOfFile_encoding_error(languagePath, NSUTF8StringEncoding, nil);
manager.loadStrings(i18n);
} else {
manager = SketchI18NPluginManager.manager();
}

if (!NSClassFromString("SketchI18NPluginManager")) {
mocha.loadFrameworkWithName_inDirectory("SketchI18NPlugin", resourcesPath + "/Contents/Resources");
manager = SketchI18NPluginManager.manager();
manager.loadStrings(i18n);
} else {
manager = SketchI18NPluginManager.manager();
}
if (identifier == "i18n-toggle-command") {
manager.toggle();
} else {
manager.run();
}
if (identifier == "i18n-toggle-command") {
manager.toggle();
} else {
manager.run();
}
}

0 comments on commit 879227e

Please sign in to comment.