Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Auto/Fast Slice bug; Plugin menu language will same as Sketch lan…
…guage; Add Select locked layers.
- Loading branch information
Ashung Hung
committed
May 29, 2021
1 parent
2803e2d
commit 206a813
Showing
8 changed files
with
109 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 13 additions & 42 deletions
55
automate-sketch.sketchplugin/Contents/Sketch/Help/Change_Languages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,26 @@ | ||
var onRun = function(context) { | ||
var onOpenDocument = function(context) { | ||
|
||
var ga = require("../modules/Google_Analytics"); | ||
ga("Help"); | ||
var preferences = require("../modules/Preferences"); | ||
var userDefaults = NSUserDefaults.standardUserDefaults(); | ||
var sketchLanguage = String(userDefaults.objectForKey("AppleLanguages").firstObject()).replace(/-\w*/, ""); | ||
var pluginLanguage = preferences.get("pluginLanguage"); | ||
|
||
var Dialog = require("../modules/Dialog").dialog; | ||
var ui = require("../modules/Dialog").ui; | ||
if (pluginLanguage != sketchLanguage) { | ||
var languageFileURL = context.plugin.urlForResourceNamed("manifest_" + sketchLanguage + ".json"); | ||
|
||
var manifestFilePath = context.plugin.url().path() + "/Contents/Sketch/manifest.json"; | ||
|
||
var supportLanguages = { | ||
"en": "English", | ||
"zh": "简体中文" | ||
}; | ||
var supportLanguagesKeys = Object.keys(supportLanguages); | ||
var supportLanguagesValues = []; | ||
for (var key in supportLanguages) { | ||
supportLanguagesValues.push(supportLanguages[""+key+""]); | ||
} | ||
|
||
// Dialog | ||
var dialog = new Dialog("Change Menu Language"); | ||
|
||
var languagesView = ui.popupButton(supportLanguagesValues); | ||
dialog.addView(languagesView); | ||
|
||
// Click OK button | ||
var responseCode = dialog.run(); | ||
if (responseCode == 1000) { | ||
var languageIndex = languagesView.indexOfSelectedItem(); | ||
var languageFileURL = context.plugin.urlForResourceNamed("manifest_" + supportLanguagesKeys[languageIndex] + ".json"); | ||
console.log(languageFileURL) | ||
if (languageFileURL) { | ||
var manifestFilePath = context.plugin.url().path() + "/Contents/Sketch/manifest.json"; | ||
var languageFilePath = languageFileURL.path(); | ||
// Remove manifest.json | ||
NSFileManager.defaultManager().removeItemAtPath_error_( | ||
manifestFilePath, nil | ||
); | ||
NSFileManager.defaultManager().removeItemAtPath_error(manifestFilePath, nil); | ||
// Replace manifest.json | ||
NSFileManager.defaultManager().copyItemAtPath_toPath_error_( | ||
languageFilePath, manifestFilePath, nil | ||
); | ||
NSFileManager.defaultManager().copyItemAtPath_toPath_error(languageFilePath, manifestFilePath, nil); | ||
// Reload Plugin | ||
AppController.sharedInstance().pluginManager().reloadPlugins(); | ||
} else { | ||
var alert = require("sketch/ui").alert; | ||
alert( | ||
"Language file not found.", | ||
"Language file \"" + context.plugin.url().path() + "/Contents/Resources/manifest_" + supportLanguagesKeys[languageIndex] + ".json\" does not existed." | ||
); | ||
} | ||
|
||
preferences.set("pluginLanguage", sketchLanguage); | ||
} | ||
} | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters