Last active
November 8, 2024 14:13
-
-
Save creold/676d8fb09c1e08d154d1db69774482d1 to your computer and use it in GitHub Desktop.
Quick access palette for changing favorite languages. Adobe Illustrator script
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
/* | |
Quick access palette for changing favorite languages in the Character panel for selected text or selected text frames. | |
Language types: | |
ENGLISH, FINNISH, STANDARDFRENCH, CANADIANFRENCH, STANDARDGERMAN, OLDGERMAN, | |
SWISSGERMAN, ITALIAN, BOKMALNORWEGIAN, NYNORSKNORWEGIAN, STANDARDPORTUGUESE, | |
BRAZILLIANPORTUGUESE, SPANISH, SWEDISH, UKENGLISH, DUTCH, DANISH, CATALAN, RUSSIAN, | |
UKRANIAN, BULGARIAN, SERBIAN, CZECH, POLISH, RUMANIAN, GREEK, TURKISH, ICELANDIC, | |
HUNGARIAN, CHINESE, JAPANESE, ARABIC, FARSI, GERMAN2006REFORM, DUTCH2005REFORM, SWISSGERMAN2006REFORM, | |
HINDI, MARATHI, BENGALIINDIA, PUNJABI, GUJARATI, ORIYA, TAMIL, TELUGU, KANNADA, MALAYALAM | |
Discussion: https://community.adobe.com/t5/illustrator-discussions/character-language-selection-gt-scripting-button-per-language/td-p/14203623 | |
Author: Sergey Osokin, email: [email protected] | |
Check my other scripts: https://github.com/creold | |
Donate (optional): | |
If you find this script helpful, you can buy me a coffee | |
- via Buymeacoffee: https://www.buymeacoffee.com/aiscripts | |
- via Donatty https://donatty.com/sergosokin | |
- via DonatePay https://new.donatepay.ru/en/@osokin | |
- via YooMoney https://yoomoney.ru/to/410011149615582 | |
*/ | |
#target illustrator | |
#targetengine langSwitcher | |
function main () { | |
var win = new Window("palette", "Language Switcher"); | |
win.preferredSize.width = 200; | |
win.spacing = 20; | |
win.alignChildren = "fill"; | |
var langs = win.add("group"); | |
langs.orientation = "column"; | |
langs.alignChildren = "fill"; | |
// You can add your own buttons for your favorite languages. | |
// In the name property, the most important thing is to specify the correct language type | |
var btnRu = langs.add("button", undefined, "Russian", { name: "RUSSIAN" }); | |
var btnUa = langs.add("button", undefined, "Ukranian", { name: "UKRANIAN" }); | |
var btnFrCa = langs.add("button", undefined, "French: Canadian", { name: "CANADIANFRENCH" }); | |
var btnEnUk = langs.add("button", undefined, "English (UK)", { name: "UKENGLISH" }); | |
var btnClose = win.add("button", undefined, "Close"); | |
for (var i = 0, len = langs.children.length; i < len; i++) { | |
langs.children[i].onClick = function () { | |
sendMessage(this.properties.name); | |
} | |
} | |
btnClose.onClick = function(){ | |
win.close(); | |
} | |
win.center(); | |
win.show(); | |
} | |
function sendMessage(name) { | |
var bt = new BridgeTalk(); | |
bt.target = BridgeTalk.appSpecifier; | |
var msg = langSwitch + "\rlangSwitch(" + name.toSource() + ");"; | |
bt.body = msg; | |
bt.send(); | |
} | |
function langSwitch(name) { | |
if (!app.documents.length) return; | |
if (!app.selection.length) return; | |
var doc = app.activeDocument; | |
var sel = doc.selection; | |
if (sel.typename === 'TextRange') { | |
sel.characterAttributes.language = LanguageType[name]; | |
} else { | |
var tfs = getTextFrames(sel); | |
for (var i = 0, len = tfs.length; i < len; i++) { | |
tfs[i].textRange.characterAttributes.language = LanguageType[name]; | |
} | |
} | |
} | |
function getTextFrames(arr) { | |
var tfs = []; | |
for (var i = 0, len = arr.length; i < len; i++) { | |
if (/text/i.test(arr[i].typename)) | |
tfs.push(arr[i]); | |
else if (/group/i.test(arr[i].typename)) | |
tfs = tfs.concat(getTextFrames(arr[i].pageItems)); | |
} | |
return tfs; | |
} | |
// Run script | |
try { | |
main(); | |
} catch (e) {} |
The language of text from Object Model Viewer (October, 2023):
ARABIC
BENGALIINDIA
BOKMALNORWEGIAN
BRAZILLIANPORTUGUESE
BULGARIAN
CANADIANFRENCH
CATALAN
CHINESE
CZECH
DANISH
DUTCH
DUTCH2005REFORM
ENGLISH
FARSI
FINNISH
GERMAN2006REFORM
GREEK
GUJARATI
HINDI
HUNGARIAN
ICELANDIC
ITALIAN
JAPANESE
KANNADA
MALAYALAM
MARATHI
NYNORSKNORWEGIAN
OLDGERMAN
ORIYA
POLISH
PUNJABI
RUMANIAN
RUSSIAN
SERBIAN
SPANISH
STANDARDFRENCH
STANDARDGERMAN
STANDARDPORTUGUESE
SWEDISH
SWISSGERMAN
SWISSGERMAN2006REFORM
TAMIL
TELUGU
TURKISH
UKENGLISH
UKRANIAN
There are differences between this list and the list of languages in the Character panel. If there is no language, "Multiple Languages" will be displayed in the panel when using the script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More about script in Telegram channel.