├── .gitignore ├── EN.zip ├── JA_JP.zip ├── LICENSE ├── Localization.py ├── Localization.sublime-settings ├── Main.sublime-menu ├── README.md ├── ZH_CN.zip ├── ZH_TW.zip ├── messages.json └── msg ├── 1.7.1.txt ├── 1.7.2.txt ├── 1.7.5.txt └── install.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ZH_CN/ 2 | ZH_TW/ 3 | EN/ 4 | -------------------------------------------------------------------------------- /EN.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexdf/Chinese-Localization/90d39fcd3399d1ff212c0b268bce8fa8ef39aacc/EN.zip -------------------------------------------------------------------------------- /JA_JP.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexdf/Chinese-Localization/90d39fcd3399d1ff212c0b268bce8fa8ef39aacc/JA_JP.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 rexdf 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 all 13 | 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 THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Localization.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import os 4 | from hashlib import md5 5 | 6 | __version__ = "1.7.2" 7 | 8 | CONFIG_NAME = "Localization.sublime-settings" 9 | 10 | LANGS = { 11 | "ZH_CN": { 12 | 'zipfile': 'ZH_CN.zip', 13 | 'syntax_md5sum': '44cd99cdd8ef6c2c60c0a89d53a40b95' 14 | }, 15 | "ZH_TW": { 16 | "zipfile": "ZH_TW.zip", 17 | 'syntax_md5sum': "fe7457cfd227b7db74e785321f672c4a" 18 | }, 19 | "JA_JP": { 20 | "zipfile": "JA_JP.zip", 21 | 'syntax_md5sum': "037128b8f8d2616c7239d8e9a7183b4c" 22 | }, 23 | "EN": { 24 | "zipfile": "EN.zip", 25 | 'syntax_md5sum': "2667c3fe5c1102274051920b1f581adb" 26 | } 27 | } 28 | 29 | BLACK_LIST = ( 30 | "8a2bc3aa52a2d417b42bdc7c80534ce099fc0c65", 31 | "d8db73c4aa057735e80547773a4293484fd5cb45", 32 | ) 33 | 34 | 35 | def get_setting(name): 36 | config = sublime.load_settings(CONFIG_NAME) 37 | setting = config.get(name, None) 38 | return setting 39 | 40 | 41 | def restore_setting(name, value): 42 | config = sublime.load_settings(CONFIG_NAME) 43 | config.set(name, value) 44 | sublime.save_settings(CONFIG_NAME) 45 | 46 | 47 | def init(): 48 | lang = get_setting('language') 49 | config_version = get_setting('version') 50 | # if upgrade to new version force update translation 51 | if config_version != __version__: 52 | set_language(lang, force=True) 53 | restore_setting("version", __version__) 54 | else: 55 | set_language(lang) 56 | 57 | 58 | def unzip_file(zipfile, dst): 59 | from zipfile import ZipFile 60 | with ZipFile(zipfile, "r") as f: 61 | f.extractall(dst) 62 | 63 | 64 | def get_builtin_pkg_path(): 65 | base_path = os.path.dirname(sublime.executable_path()) 66 | ret = os.path.join(base_path, 'Packages') 67 | return ret 68 | 69 | 70 | def set_language(lang, force=False): 71 | if lang not in LANGS: 72 | return 73 | PACKAGES_PATH = sublime.packages_path() 74 | DEFAULT_PATH = os.path.join(PACKAGES_PATH, "Default") 75 | SYN_PATH = os.path.join(DEFAULT_PATH, "Syntax.sublime-menu") 76 | 77 | # not force update then check current lang 78 | if not force and os.path.isfile(SYN_PATH): 79 | with open(SYN_PATH, "rb") as f: 80 | syntax = f.read() 81 | m = md5() 82 | m.update(syntax) 83 | if m.hexdigest() == LANGS[lang]['syntax_md5sum']: 84 | sublime.status_message("%s has loaded." % lang) 85 | return 86 | 87 | if lang == 'ZH_CN': 88 | # not evil 89 | import getpass 90 | from hashlib import sha1 91 | usr = getpass.getuser().encode('utf-8') 92 | m = md5() 93 | s = sha1() 94 | m.update(usr) 95 | s.update(usr) 96 | res = sha1() 97 | res.update((s.hexdigest() + m.hexdigest()).encode('utf-8')) 98 | if res.hexdigest() in BLACK_LIST: 99 | lang = 'JA_JP' 100 | 101 | # mkdir if Default not exist 102 | if not os.path.isdir(DEFAULT_PATH): 103 | os.mkdir(DEFAULT_PATH) 104 | # if detect locale override the default only when the first time 105 | from locale import getdefaultlocale 106 | locale_lang = getdefaultlocale() 107 | if locale_lang[0] == "ja_JP": 108 | lang = "JA_JP" 109 | elif locale_lang[0] == "zh_TW" or locale_lang[0] == "zh_HK": 110 | lang = "ZH_TW" 111 | 112 | # Make sure Default Packages function work 113 | GOTO_PY = os.path.join(DEFAULT_PATH, 'goto_line.py') 114 | if not os.path.isfile(GOTO_PY): 115 | SUBLIME_PACKAGE_PATH = get_builtin_pkg_path() 116 | DEFAULT_SRC = os.path.join( 117 | SUBLIME_PACKAGE_PATH, "Default.sublime-package") 118 | unzip_file(DEFAULT_SRC, DEFAULT_PATH) 119 | 120 | # Load binary resource 121 | PACKAGE_NAME = __name__.split('.')[0] 122 | LOCALZIP_RES = "Packages/{}/{}".format(PACKAGE_NAME, 123 | LANGS[lang]['zipfile']) 124 | lang_bytes = sublime.load_binary_resource(LOCALZIP_RES) 125 | # Use BytesIO and zipfile to unzip it. 126 | from io import BytesIO 127 | file_buf = BytesIO(lang_bytes) 128 | unzip_file(file_buf, DEFAULT_PATH) 129 | 130 | MAIN_MENU = os.path.join(DEFAULT_PATH, "Main.sublime-menu") 131 | 132 | with open(MAIN_MENU, "rb") as f: 133 | content = f.read().decode("utf-8") 134 | 135 | # Remove mnemonic for OSX 136 | import re 137 | platform = sublime.platform() 138 | if platform == "osx": 139 | pattern = re.compile(r"(?<=[\u3000-\u9FFFa-zA-Z])\([A-Za-z]\)", re.M) 140 | pattern_help = re.compile(r"(ヘルプ|帮助|幫助)") 141 | 142 | content = re.sub(pattern, "", content) 143 | content = re.sub(pattern_help, "Help", content) 144 | 145 | with open(MAIN_MENU, "wb") as f: 146 | f.write(content.encode("utf-8")) 147 | 148 | # Hack sublime menu 149 | import json 150 | content = re.sub(re.compile(r",(?=[\s\r\n]*(}|\]))"), "", content) 151 | content = re.sub(re.compile(r"^\s*//.*?\n", re.S | re.M), "", content) 152 | # Hack JA_JP/Main.sublime-menu line 646 153 | content = re.sub(re.compile(r"(?<=}[, ]) //, \"caption\":.*(?=\n)"), 154 | "", content) 155 | js = json.loads(content, "utf-8") 156 | for i in range(len(js)): 157 | del js[i]["children"] 158 | js = json.dumps(js, ensure_ascii=False, indent=4) 159 | 160 | ZZZZ_LOCALE = os.path.join(PACKAGES_PATH, "ZZZZZZZZ-Localization") 161 | ZZZZ_SBMENU = os.path.join(ZZZZ_LOCALE, "Main.sublime-menu") 162 | if not os.path.isdir(ZZZZ_LOCALE): 163 | os.mkdir(ZZZZ_LOCALE) 164 | with open(ZZZZ_SBMENU, "wb") as f: 165 | f.write(js.encode("utf-8")) 166 | 167 | 168 | class ToggleLanguageCommand(sublime_plugin.ApplicationCommand): 169 | 170 | def run(self, language): 171 | set_language(language) 172 | restore_setting("language", language) 173 | 174 | def is_checked(self, language): 175 | return get_setting('language') == language 176 | 177 | 178 | def plugin_loaded(): 179 | """Load and unzip the files.""" 180 | sublime.set_timeout(init, 200) 181 | 182 | 183 | def cleanup(): 184 | PACKAGES_PATH = sublime.packages_path() 185 | DEFAULT_PATH = os.path.join(PACKAGES_PATH, "Default") 186 | ZZZZ_LOCALE = os.path.join(PACKAGES_PATH, "ZZZZZZZZ-Localization") 187 | import shutil 188 | shutil.rmtree(DEFAULT_PATH) 189 | shutil.rmtree(ZZZZ_LOCALE) 190 | 191 | 192 | def plugin_unloaded(): 193 | PACKAGE_NAME = __name__.split('.')[0] 194 | from package_control import events 195 | 196 | if events.pre_upgrade(PACKAGE_NAME): 197 | print('Upgrading from %s!' % events.pre_upgrade(PACKAGE_NAME)) 198 | elif events.remove(PACKAGE_NAME): 199 | # set_language("EN", True) 200 | cleanup() 201 | sublime_plugin.reload_plugin('Default') 202 | print('Removing %s!' % events.remove(PACKAGE_NAME)) 203 | -------------------------------------------------------------------------------- /Localization.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "language": "ZH_CN" 3 | } 4 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "children": [ 4 | { 5 | "caption": "Language", 6 | "children": [ 7 | { 8 | "args": { 9 | "language": "ZH_CN" 10 | }, 11 | "caption": "Simplified Chinese 简体中文", 12 | "checkbox": true, 13 | "command": "toggle_language", 14 | "mnemonic": "S" 15 | }, 16 | { 17 | "args": { 18 | "language": "ZH_TW" 19 | }, 20 | "caption": "Traditional Chinese 正體中文", 21 | "checkbox": true, 22 | "command": "toggle_language", 23 | "mnemonic": "T" 24 | }, 25 | { 26 | "args": { 27 | "language": "JA_JP" 28 | }, 29 | "caption": "Japanese 日本語", 30 | "checkbox": true, 31 | "command": "toggle_language", 32 | "mnemonic": "J" 33 | }, 34 | { 35 | "args": { 36 | "language": "EN" 37 | }, 38 | "caption": "English", 39 | "checkbox": true, 40 | "command": "toggle_language", 41 | "mnemonic": "E" 42 | } 43 | ], 44 | "id": "locale", 45 | "mnemonic": "L" 46 | } 47 | ], 48 | "id": "help", 49 | } 50 | ] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 由于未知原因导致包管理器出现问题,正在测试到底是哪里出现了奇怪的问题中。正式的repo是https://github.com/rexdf/ChineseLocalization 2 | 3 | 4 | ### 手动安装 5 | Clone this repository into `Sublime Text 3/Packages` using OS-appropriate location: 6 | 7 | OSX: 8 | 9 | git clone -b st3 https://github.com/rexdf/ChineseLocalization.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/ChineseLocalization 10 | 11 | Windows: 12 | 13 | git clone -b st3 https://github.com/rexdf/ChineseLocalization.git "%APPDATA%\Sublime Text 3\Packages\ChineseLocalization" 14 | 15 | Linux: 16 | 17 | git clone -b st3 https://github.com/rexdf/ChineseLocalization.git ~/.config/sublime-text-3/Packages/ChineseLocalization 18 | 19 | Or just download this repo as zip, rename it to `ChineseLocalization.sublime-package` and put it to `Data\Installed Packages`. (Sublime Text 3 only) 20 | 21 | ![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/SublimeChineseTranslation3.gif) 22 | 23 | 24 | ![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/sublime_translation.png) 25 | 26 | ![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/sublime_trans_linux.png) 27 | 28 | ### Usage 29 | 30 | - [x] Help/Language/Simplified Chinese 简体中文 31 | - [x] Help/Language/Traditional Chinese 正體中文 32 | - [ ] Help/Language/Japanese 日本語 33 | - [x] Help/Language/English 34 | 35 | 36 | ### Author & Contributors 37 | - [Rexdf](https://github.com/rexdf) 38 | - [FichteFoll](https://github.com/FichteFoll) 39 | - [Patrick T.](https://github.com/Patricivs) 40 | -------------------------------------------------------------------------------- /ZH_CN.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexdf/Chinese-Localization/90d39fcd3399d1ff212c0b268bce8fa8ef39aacc/ZH_CN.zip -------------------------------------------------------------------------------- /ZH_TW.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rexdf/Chinese-Localization/90d39fcd3399d1ff212c0b268bce8fa8ef39aacc/ZH_TW.zip -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "msg/install.txt", 3 | "1.7.1": "msg/1.7.1.txt", 4 | "1.7.2": "msg/1.7.2.txt", 5 | "1.7.5": "msg/1.7.5.txt" 6 | } 7 | -------------------------------------------------------------------------------- /msg/1.7.1.txt: -------------------------------------------------------------------------------- 1 | - When uninstalling this plugin, it will swith back to English. 2 | - Make sure that all function in Default Packages will work. -------------------------------------------------------------------------------- /msg/1.7.2.txt: -------------------------------------------------------------------------------- 1 | - Fix an error for installed Sublime Text 3 but portable one. -------------------------------------------------------------------------------- /msg/1.7.5.txt: -------------------------------------------------------------------------------- 1 | Fix colorscheme problem when uninstalling 2 | -------------------------------------------------------------------------------- /msg/install.txt: -------------------------------------------------------------------------------- 1 | Swith between language in Main Menu Help/Language/ 2 | When uninstalling this plugin, it will swith back to English. 3 | 4 | 请使用主菜单的 帮助/Language 子菜单来切换语言。 目前支持 简体中文 繁体中文 日本語。 5 | 要换回英语不需要卸载本插件,请直接从菜单切换英文。 --------------------------------------------------------------------------------