var onRun = function(context) {
    var manager,
        doc = context.document,
        command = context.command,
        identifier = command.identifier(),
        resourcesPath = command.pluginBundle().url().path(),
        language = NSUserDefaults.standardUserDefaults().objectForKey("AppleLanguages").objectAtIndex(0),
        languagePath = resourcesPath + "/Contents/Resources/i18n/" + language + ".json";

    if (NSFileManager.defaultManager().fileExistsAtPath(languagePath)) {
        var mocha = Mocha.sharedRuntime();
        i18n = [NSString stringWithContentsOfFile: languagePath encoding: NSUTF8StringEncoding error: nil];

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

@@ -42,16 +42,38 @@
 anager,%0A
+        languagePath,%0A
         
@@ -339,17 +339,31 @@
 Index(0)
-,
+;%0A%0A    for(;;)%7B
 %0A       
@@ -444,17 +444,20 @@
 .json%22;%0A
-%0A
+    
     if (
@@ -533,156 +533,234 @@
     
-var mocha = Mocha.sharedRuntime();%0A        i18n = %5BNSString stringWithContentsOfFile: languagePath encoding: NSUTF8StringEncoding error: nil%5D;%0A
+    break;%0A        %7D%0A        else %7B%0A            var index = language.lastIndexOf(%22-%22);%0A            if (index == -1) %7B%0A                return;%0A            %7D%0A            language = language.substring(0, index);%0A        %7D
 %0A    
+%7D%0A%0A
     
@@ -808,32 +808,71 @@
 anager%22)) %7B%0A    
+    var mocha = Mocha.sharedRuntime();%0A
         mocha.lo
@@ -963,36 +963,32 @@
 rces%22);%0A        
-    
 manager = Sketch
@@ -1016,24 +1016,130 @@
 ager();%0A    
+    var i18n = NSString.stringWithContentsOfFile_encoding_error(languagePath, NSUTF8StringEncoding, nil);%0A
         mana
@@ -1161,20 +1161,16 @@
 (i18n);%0A
-    
     %7D el
@@ -1166,36 +1166,32 @@
 );%0A    %7D else %7B%0A
-    
         manager 
@@ -1227,34 +1227,27 @@
 ager();%0A    
-   
- 
 %7D%0A
-    
+%0A
     if (iden
@@ -1281,36 +1281,32 @@
 and%22) %7B%0A        
-    
 manager.toggle()
@@ -1303,28 +1303,24 @@
 r.toggle();%0A
-    
     %7D else %7B
@@ -1324,28 +1324,24 @@
 e %7B%0A        
-    
 manager.run(
@@ -1343,26 +1343,16 @@
 .run();%0A
-        %7D%0A
     %7D%0A%7D%0A

fix macOS locale issues #47