├── .gitignore ├── icon.png ├── media ├── ls.png ├── config.png └── config2.png ├── license ├── package.json ├── info.plist ├── README.md ├── languages.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | package-lock.json -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xfslove/alfred-language-configuration/HEAD/icon.png -------------------------------------------------------------------------------- /media/ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xfslove/alfred-language-configuration/HEAD/media/ls.png -------------------------------------------------------------------------------- /media/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xfslove/alfred-language-configuration/HEAD/media/config.png -------------------------------------------------------------------------------- /media/config2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xfslove/alfred-language-configuration/HEAD/media/config2.png -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alfred-language-configuration", 3 | "version": "1.0.4", 4 | "description": "Alfred 3 workflow alfred-google-translate language configuration", 5 | "license": "MIT", 6 | "repository": "xfslove/alfred-language-configuration", 7 | "author": { 8 | "name": "hanwen.huang", 9 | "email": "xfslove@gmail.com", 10 | "url": "https://github.com/xfslove/alfred-language-configuration" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava", 17 | "postinstall": "alfy-init", 18 | "preuninstall": "alfy-cleanup" 19 | }, 20 | "files": [ 21 | "index.js", 22 | "languages.js", 23 | "icon.png", 24 | "info.plist" 25 | ], 26 | "keywords": [ 27 | "translate", 28 | "google-translate", 29 | "alfred", 30 | "alfred-workflow", 31 | "workflow", 32 | "alfy" 33 | ], 34 | "dependencies": { 35 | "alfy": "^0.9.0", 36 | "configstore": "^2.0.0" 37 | }, 38 | "devDependencies": { 39 | "alfy-test": "^0.3.0", 40 | "puppeteer": "^1.11.0", 41 | "codecov": "^3.6.5", 42 | "coveralls": "^2.11.11", 43 | "nyc": "^7.0.0", 44 | "ava": "*", 45 | "xo": "*" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleid 6 | com.xfslove.language-configuration 7 | category 8 | Tools 9 | connections 10 | 11 | createdby 12 | hanwen.huang 13 | description 14 | The pre-workfow of Google Translate for config language pair 15 | disabled 16 | 17 | name 18 | Translate Language Configuration 19 | objects 20 | 21 | 22 | config 23 | 24 | alfredfiltersresults 25 | 26 | alfredfiltersresultsmatchmode 27 | 0 28 | argumenttrimmode 29 | 0 30 | argumenttype 31 | 0 32 | escaping 33 | 102 34 | keyword 35 | trc 36 | queuedelaycustom 37 | 3 38 | queuedelayimmediatelyinitially 39 | 40 | queuedelaymode 41 | 2 42 | queuemode 43 | 2 44 | runningsubtext 45 | Config... 46 | script 47 | ./node_modules/.bin/run-node index.js "$1" 48 | scriptargtype 49 | 1 50 | scriptfile 51 | 52 | subtext 53 | 54 | title 55 | language configuration 56 | type 57 | 0 58 | withspace 59 | 60 | 61 | type 62 | alfred.workflow.input.scriptfilter 63 | uid 64 | B35CF386-442E-4127-95B3-ABC81997F637 65 | version 66 | 2 67 | 68 | 69 | readme 70 | 71 | uidata 72 | 73 | B35CF386-442E-4127-95B3-ABC81997F637 74 | 75 | xpos 76 | 340 77 | ypos 78 | 160 79 | 80 | 81 | webaddress 82 | https://github.com/xfslove/alfred-language-configuration#readme 83 | 84 | 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alfred-language-configuration 2 | 3 | [![NPM](https://nodei.co/npm/alfred-language-configuration.png)](https://nodei.co/npm/alfred-language-configuration/) 4 | 5 | ## Installation 6 | 7 | *Requires the Alfred 3 or 4 [Powerpack](https://www.alfredapp.com/powerpack/), [Node.js](https://nodejs.org) 8+, and the original [alfred-google-translate](https://github.com/xfslove/alfred-google-translate) workflow.* 8 | 9 | ### With NPM 10 | - Install the original workflow with `npm install -g alfred-google-translate`. 11 | - Install this configuration workflow with `npm install -g alfred-language-configuration`. 12 | 13 | ### Manually 14 | - Install the original [alfred-google-translate](https://github.com/xfslove/alfred-google-translate) workflow. 15 | - Install this [alfred-language-configuration](https://github.com/xfslove/alfred-language-configuration/releases/tag/v1.0.3) workflow. 16 | 17 | ## Changelog 18 | See [all past and current releases](https://github.com/xfslove/alfred-language-configuration/releases). 19 | 20 | ## Usage 21 | 22 | - Assign a *source* and *target* langauge by either… (See [Supported Language List](#supported-language-list)) 23 | - **Choosing a bi-directional langauge pair** which will auto-translate either direction using `trc [source language keyword]&[target language keyword]` (For example `trc en&zh-CN` will cause the translate workflow to autodetect the target language so `tr hello` will display a Chinese translation and `tr 你好` will display an English translation.). 24 | - ***OR*** by **Choosing a one-way translation pair** using `trc [source language keyword]>[target language keyword]` (For example `trc en>zh-CN` will cause the translate workflow to only translate from English to Chinese.). 25 | 26 | - Get the current configuration with `trc ls`. 27 | 28 | ## Screenshots 29 | 30 | ![config2.png](media/config2.png) 31 | 32 | ![config.png](media/config.png) 33 | 34 | ![ls.png](media/ls.png) 35 | 36 | ## Supported Language List 37 | 38 | | keyword | language | 39 | | --------- | ------- | 40 | |af|Afrikaans| 41 | |sq|Albanian| 42 | |am|Amharic| 43 | |ar|Arabic| 44 | |hy|Armenian| 45 | |az|Azerbaijani| 46 | |eu|Basque| 47 | |be|Belarusian| 48 | |bn|Bengali| 49 | |bs|Bosnian| 50 | |bg|Bulgarian| 51 | |ca|Catalan| 52 | |ceb|Cebuano| 53 | |ny|Chichewa| 54 | |zh-CN|Chinese Simplified| 55 | |zh-TW|Chinese Traditional| 56 | |co|Corsican| 57 | |hr|Croatian| 58 | |cs|Czech| 59 | |da|Danish| 60 | |nl|Dutch| 61 | |en|English| 62 | |eo|Esperanto| 63 | |et|Estonian| 64 | |tl|Filipino| 65 | |fi|Finnish| 66 | |fr|French| 67 | |fy|Frisian| 68 | |gl|Galician| 69 | |ka|Georgian| 70 | |de|German| 71 | |el|Greek| 72 | |gu|Gujarati| 73 | |ht|Haitian Creole| 74 | |ha|Hausa| 75 | |haw|Hawaiian| 76 | |he|Hebrew| 77 | |iw|Hebrew| 78 | |hi|Hindi| 79 | |hmn|Hmong| 80 | |hu|Hungarian| 81 | |is|Icelandic| 82 | |ig|Igbo| 83 | |id|Indonesian| 84 | |ga|Irish| 85 | |it|Italian| 86 | |ja|Japanese| 87 | |jw|Javanese| 88 | |kn|Kannada| 89 | |kk|Kazakh| 90 | |km|Khmer| 91 | |ko|Korean| 92 | |ku|Kurdish (Kurmanji)| 93 | |ky|Kyrgyz| 94 | |lo|Lao| 95 | |la|Latin| 96 | |lv|Latvian| 97 | |lt|Lithuanian| 98 | |lb|Luxembourgish| 99 | |mk|Macedonian| 100 | |mg|Malagasy| 101 | |ms|Malay| 102 | |ml|Malayalam| 103 | |mt|Maltese| 104 | |mi|Maori| 105 | |mr|Marathi| 106 | |mn|Mongolian| 107 | |my|Myanmar (Burmese)| 108 | |ne|Nepali| 109 | |no|Norwegian| 110 | |ps|Pashto| 111 | |fa|Persian| 112 | |pl|Polish| 113 | |pt|Portuguese| 114 | |pa|Punjabi| 115 | |ro|Romanian| 116 | |ru|Russian| 117 | |sm|Samoan| 118 | |gd|Scots Gaelic| 119 | |sr|Serbian| 120 | |sr-Latn|Serbian Latin| 121 | |st|Sesotho| 122 | |sn|Shona| 123 | |sd|Sindhi| 124 | |si|Sinhala| 125 | |sk|Slovak| 126 | |sl|Slovenian| 127 | |so|Somali| 128 | |es|Spanish| 129 | |su|Sundanese| 130 | |sw|Swahili| 131 | |sv|Swedish| 132 | |tg|Tajik| 133 | |ta|Tamil| 134 | |te|Telugu| 135 | |th|Thai| 136 | |tr|Turkish| 137 | |uk|Ukrainian| 138 | |ur|Urdu| 139 | |uz|Uzbek| 140 | |vi|Vietnamese| 141 | |cy|Welsh| 142 | |xh|Xhosa| 143 | |yi|Yiddish| 144 | |yo|Yoruba| 145 | |zu|Zulu| 146 | -------------------------------------------------------------------------------- /languages.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Generated from https://translate.google.com 4 | * 5 | * The languages that Google Translate supports (as of 5/15/16) alongside with their ISO 639-1 codes 6 | * See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes 7 | */ 8 | 9 | var langs = { 10 | 'auto': 'Automatic', 11 | 'af': 'Afrikaans', 12 | 'sq': 'Albanian', 13 | 'am': 'Amharic', 14 | 'ar': 'Arabic', 15 | 'hy': 'Armenian', 16 | 'az': 'Azerbaijani', 17 | 'eu': 'Basque', 18 | 'be': 'Belarusian', 19 | 'bn': 'Bengali', 20 | 'bs': 'Bosnian', 21 | 'bg': 'Bulgarian', 22 | 'ca': 'Catalan', 23 | 'ceb': 'Cebuano', 24 | 'ny': 'Chichewa', 25 | 'zh-CN': 'Chinese Simplified', 26 | 'zh-TW': 'Chinese Traditional', 27 | 'co': 'Corsican', 28 | 'hr': 'Croatian', 29 | 'cs': 'Czech', 30 | 'da': 'Danish', 31 | 'nl': 'Dutch', 32 | 'en': 'English', 33 | 'eo': 'Esperanto', 34 | 'et': 'Estonian', 35 | 'tl': 'Filipino', 36 | 'fi': 'Finnish', 37 | 'fr': 'French', 38 | 'fy': 'Frisian', 39 | 'gl': 'Galician', 40 | 'ka': 'Georgian', 41 | 'de': 'German', 42 | 'el': 'Greek', 43 | 'gu': 'Gujarati', 44 | 'ht': 'Haitian Creole', 45 | 'ha': 'Hausa', 46 | 'haw': 'Hawaiian', 47 | 'he': 'Hebrew', 48 | 'iw': 'Hebrew', 49 | 'hi': 'Hindi', 50 | 'hmn': 'Hmong', 51 | 'hu': 'Hungarian', 52 | 'is': 'Icelandic', 53 | 'ig': 'Igbo', 54 | 'id': 'Indonesian', 55 | 'ga': 'Irish', 56 | 'it': 'Italian', 57 | 'ja': 'Japanese', 58 | 'jw': 'Javanese', 59 | 'kn': 'Kannada', 60 | 'kk': 'Kazakh', 61 | 'km': 'Khmer', 62 | 'ko': 'Korean', 63 | 'ku': 'Kurdish (Kurmanji)', 64 | 'ky': 'Kyrgyz', 65 | 'lo': 'Lao', 66 | 'la': 'Latin', 67 | 'lv': 'Latvian', 68 | 'lt': 'Lithuanian', 69 | 'lb': 'Luxembourgish', 70 | 'mk': 'Macedonian', 71 | 'mg': 'Malagasy', 72 | 'ms': 'Malay', 73 | 'ml': 'Malayalam', 74 | 'mt': 'Maltese', 75 | 'mi': 'Maori', 76 | 'mr': 'Marathi', 77 | 'mn': 'Mongolian', 78 | 'my': 'Myanmar (Burmese)', 79 | 'ne': 'Nepali', 80 | 'no': 'Norwegian', 81 | 'ps': 'Pashto', 82 | 'fa': 'Persian', 83 | 'pl': 'Polish', 84 | 'pt': 'Portuguese', 85 | 'pa': 'Punjabi', 86 | 'ro': 'Romanian', 87 | 'ru': 'Russian', 88 | 'sm': 'Samoan', 89 | 'gd': 'Scots Gaelic', 90 | 'sr': 'Serbian', 91 | 'sr-Latn': 'Serbian Latin', 92 | 'st': 'Sesotho', 93 | 'sn': 'Shona', 94 | 'sd': 'Sindhi', 95 | 'si': 'Sinhala', 96 | 'sk': 'Slovak', 97 | 'sl': 'Slovenian', 98 | 'so': 'Somali', 99 | 'es': 'Spanish', 100 | 'su': 'Sundanese', 101 | 'sw': 'Swahili', 102 | 'sv': 'Swedish', 103 | 'tg': 'Tajik', 104 | 'ta': 'Tamil', 105 | 'te': 'Telugu', 106 | 'th': 'Thai', 107 | 'tr': 'Turkish', 108 | 'uk': 'Ukrainian', 109 | 'ur': 'Urdu', 110 | 'uz': 'Uzbek', 111 | 'vi': 'Vietnamese', 112 | 'cy': 'Welsh', 113 | 'xh': 'Xhosa', 114 | 'yi': 'Yiddish', 115 | 'yo': 'Yoruba', 116 | 'zu': 'Zulu' 117 | }; 118 | /** 119 | * Returns the ISO 639-1 code of the desiredLang – if it is supported by Google Translate 120 | * @param {string} desiredLang – the name or the code of the desired language 121 | * @returns {string|boolean} The ISO 639-1 code of the language or false if the language is not supported 122 | */ 123 | function getCode(desiredLang) { 124 | if (!desiredLang) { 125 | return false; 126 | } 127 | 128 | if (langs[desiredLang]) { 129 | return desiredLang; 130 | } 131 | 132 | var keys = Object.keys(langs).filter(function (key) { 133 | if (typeof langs[key] !== 'string') { 134 | return false; 135 | } 136 | 137 | return langs[key] === desiredLang; 138 | }); 139 | 140 | return keys[0] || false; 141 | } 142 | 143 | /** 144 | * Returns true if the desiredLang is supported by Google Translate and false otherwise 145 | * @param desiredLang – the ISO 639-1 code or the name of the desired language 146 | * @returns {boolean} 147 | */ 148 | function isSupported(desiredLang) { 149 | return Boolean(getCode(desiredLang)); 150 | } 151 | 152 | module.exports = langs; 153 | module.exports.isSupported = isSupported; 154 | module.exports.getCode = getCode; 155 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const alfy = require('alfy'); 3 | const language = require('./languages.js'); 4 | const configstore = require('configstore'); 5 | const languagePair = new configstore('language-config-pair'); 6 | 7 | const q = alfy.input; 8 | 9 | var items = []; 10 | if (q === 'ls') { 11 | var pair = 'Not'; 12 | if (languagePair.get('pair')) { 13 | pair = languagePair.get('pair').join('&'); 14 | } else if (languagePair.get('source') && languagePair.get('target')) { 15 | pair = `${languagePair.get('source')}>${languagePair.get('target')}`; 16 | } 17 | items.push({ 18 | title: `Current, [${pair}] assigned.` 19 | }); 20 | } else if (q.indexOf('>') === -1 && q.indexOf('&') === -1) { 21 | items.push({ 22 | title: `Failure, must contain \'>\' or\' &\'`, 23 | subtitle: `configuration format: source>target or first one&the second.`, 24 | icon: { 25 | path: alfy.icon.error 26 | } 27 | }); 28 | } else if (q.indexOf('>') !== -1 && q.indexOf('&') !== -1) { 29 | items.push({ 30 | title: `Failure, \'>\' or \'&\' must contain only one.`, 31 | subtitle: `configuration format: source>target or first one&the second.`, 32 | icon: { 33 | path: alfy.icon.error 34 | } 35 | }); 36 | } else if (q.indexOf('>') === -1) { 37 | // auto 38 | var pair = q.split('&'); 39 | if (pair.length !== 2) { 40 | items.push({ 41 | title: `Failure, \'&\' must contain only one.`, 42 | subtitle: `configuration format: first one&the second.`, 43 | icon: { 44 | path: alfy.icon.error 45 | } 46 | }); 47 | } else { 48 | var pair0 = language.getCode(pair[0]); 49 | var pair1 = language.getCode(pair[1]); 50 | 51 | if (!pair0 && !pair1) { 52 | items.push({ 53 | title: `Failure, first[${pair[0]}] and second[${pair[1]}] languages not supported.`, 54 | subtitle: `Press shift to see full support languages.`, 55 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 56 | icon: { 57 | path: alfy.icon.error 58 | } 59 | }); 60 | } else if (!pair0) { 61 | items.push({ 62 | title: `Failure, first[${pair[0]}] language not supported.`, 63 | subtitle: `Press shift to see full support languages.`, 64 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 65 | icon: { 66 | path: alfy.icon.error 67 | } 68 | }); 69 | } else if (!pair1) { 70 | items.push({ 71 | title: `Failure, second[${pair[1]}] language not supported.`, 72 | subtitle: `Press shift to see full support languages.`, 73 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 74 | icon: { 75 | path: alfy.icon.error 76 | } 77 | }); 78 | } else { 79 | languagePair.delete('source'); 80 | languagePair.delete('target'); 81 | languagePair.set('pair', pair); 82 | items.push({ 83 | title: `Success, [${q}] assigned.` 84 | }); 85 | } 86 | } 87 | } else { 88 | // manual 89 | var pair = q.split('>'); 90 | if (pair.length !== 2) { 91 | items.push({ 92 | title: `Failure, \'>\' must contain only one.`, 93 | subtitle: `configuration format: source>target or first one&the second.`, 94 | icon: { 95 | path: alfy.icon.error 96 | } 97 | }); 98 | } else { 99 | var pair0 = language.getCode(pair[0]); 100 | var pair1 = language.getCode(pair[1]); 101 | 102 | if (!pair0 && !pair1) { 103 | items.push({ 104 | title: `Failure, source[${pair[0]}] and target[${pair[1]}] languages not supported.`, 105 | subtitle: `Press shift to see full support languages.`, 106 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 107 | icon: { 108 | path: alfy.icon.error 109 | } 110 | }); 111 | } else if (!pair0) { 112 | items.push({ 113 | title: `Failure, source[${pair[0]}] language not supported.`, 114 | subtitle: `Press shift to see full support languages.`, 115 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 116 | icon: { 117 | path: alfy.icon.error 118 | } 119 | }); 120 | } else if (!pair1) { 121 | items.push({ 122 | title: `Failure, target[${pair[1]}] language not supported.`, 123 | subtitle: `Press shift to see full support languages.`, 124 | quicklookurl: 'https://github.com/xfslove/alfred-language-configuration#readme', 125 | icon: { 126 | path: alfy.icon.error 127 | } 128 | }); 129 | } else { 130 | languagePair.delete('pair'); 131 | languagePair.set('source', pair0); 132 | languagePair.set('target', pair1); 133 | items.push({ 134 | title: `Success, [${q}] assigned.` 135 | }); 136 | } 137 | 138 | } 139 | } 140 | 141 | alfy.output(items); 142 | --------------------------------------------------------------------------------