diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..5fc9ea2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +ZH_CN/ +ZH_TW/ +EN/ \ No newline at end of file diff --git a/EN.zip b/EN.zip index e831229..967bd44 100755 Binary files a/EN.zip and b/EN.zip differ diff --git a/Localization.py b/Localization.py index 8619d54..cc422f2 100755 --- a/Localization.py +++ b/Localization.py @@ -1,6 +1,7 @@ import sublime import sublime_plugin import os +import sys from hashlib import md5 CONFIG_NAME = "Localization.sublime-settings" @@ -20,6 +21,9 @@ } } +is_python3 = sys.version_info[0] > 2 +CUR_PATH = os.path.dirname(os.path.realpath(__file__)) + def get_language_setting(): config = sublime.load_settings(CONFIG_NAME) @@ -59,18 +63,31 @@ def set_language(lang): if not os.path.isdir(DEFAULT_PATH): os.mkdir(DEFAULT_PATH) # Load binary resource - PACKAGE_NAME = os.path.basename(os.path.dirname(__file__)).split('.')[0] - LOCALZIP_RES = "Packages/{}/{}".format(PACKAGE_NAME, - LANGS[lang]['zipfile']) - lang_bytes = sublime.load_binary_resource(LOCALZIP_RES) + if is_python3: + PACKAGE_NAME = os.path.basename(os.path.dirname(__file__)).split('.')[0] + LOCALZIP_RES = "Packages/{0}/{1}".format(PACKAGE_NAME, + LANGS[lang]['zipfile']) + try: + lang_bytes = sublime.load_binary_resource(LOCALZIP_RES) + except Exception: + # Sublime Text 2 + LOCALZIP_RES = os.path.abspath(os.path.join(CUR_PATH, + LANGS[lang]['zipfile'])) + with open(LOCALZIP_RES, "rb") as f: + lang_bytes = f.read() # write to tempfile and unzip it. import zipfile from tempfile import NamedTemporaryFile tmp_file = NamedTemporaryFile(delete=False) tmp_file.write(lang_bytes) tmp_file.close() - with zipfile.ZipFile(tmp_file.name, "r") as f: - f.extractall(DEFAULT_PATH) + if is_python3: + with zipfile.ZipFile(tmp_file.name, "r") as f: + f.extractall(DEFAULT_PATH) + else: + import contextlib + with contextlib.closing(zipfile.ZipFile(tmp_file.name, "r")) as f: + f.extractall(DEFAULT_PATH) tmp_file.close() os.unlink(tmp_file.name) @@ -87,4 +104,7 @@ def is_checked(self, language): def plugin_loaded(): """Load and unzip the files.""" - sublime.set_timeout(init, 200) \ No newline at end of file + sublime.set_timeout(init, 200) + +if not is_python3: + init() \ No newline at end of file diff --git a/Main.sublime-menu b/Main.sublime-menu index 76da554..53f17fc 100755 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -36,6 +36,6 @@ "mnemonic": "L" } ], - "id": "help", + "id": "help" } ] \ No newline at end of file diff --git a/README.md b/README.md index 34701f0..c94a2bd 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,31 @@ # Chinese-Localization Simplified Chinese and Traditional Chinese Translation for Sublime Text 3. Support MainMenu TabMenu ContextMenu,etc +**Upgrade to sublime text 3 to have a better experience.** + ### Manual Install Clone this repository into `Sublime Text 3/Packages` using OS-appropriate location: OSX: - git clone https://github.com/rexdf/Chinese-Localization.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/ChineseLocalization + git clone -b st2 https://github.com/rexdf/ChineseLocalization.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/ChineseLocalization Windows: - git clone https://github.com/rexdf/Chinese-Localization.git "%APPDATA%\Sublime Text 3\Packages\ChineseLocalization" + git clone -b st2 https://github.com/rexdf/Chinese-Localization.git "%APPDATA%\Sublime Text 3\Packages\ChineseLocalization" Linux: - git clone https://github.com/rexdf/Chinese-Localization.git ~/.config/sublime-text-3/Packages/ChineseLocalization + git clone -b st2 https://github.com/rexdf/Chinese-Localization.git ~/.config/sublime-text-3/Packages/ChineseLocalization Or just download this repo as zip and unzip it to `Packages/Default` -![screenshot](https://raw.githubusercontent.com/rexdf/Chinese-Localization/readme/screenshot/SublimeChineseTranslation2.gif) +![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/SublimeChineseTranslation3.gif) -![screenshot](https://raw.githubusercontent.com/rexdf/Chinese-Localization/readme/screenshot/sublime_translation.png) +![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/sublime_translation.png) -![screenshot](https://raw.githubusercontent.com/rexdf/Chinese-Localization/readme/screenshot/sublime_trans_linux.png) +![screenshot](https://raw.githubusercontent.com/rexdf/ChineseLocalization/readme/screenshot/sublime_trans_linux.png) ### Usage @@ -35,7 +37,7 @@ Or just download this repo as zip and unzip it to `Packages/Default` ### problems Because almost every package has a `Main.sublime-menu`, So some package name maybe override the Default one. -AFAIK, +AFAIK, minimal manual delete including: + **SublimeREPL** delete caption @@ -45,4 +47,10 @@ AFAIK, + **Indent XML** delete caption Selection -+ **GraphvizPreview** delete caption Edit \ No newline at end of file ++ **HTMLBeautify** delete caption Edit + ++ **GraphvizPreview** delete caption Edit + +### Author & Contributors +- [Rexdf](https://github.com/rexdf) +- [FichteFoll](https://github.com/FichteFoll) diff --git a/ZH_CN.zip b/ZH_CN.zip index b4ae3ec..226032a 100755 Binary files a/ZH_CN.zip and b/ZH_CN.zip differ diff --git a/ZH_TW.zip b/ZH_TW.zip index 39fd5fb..6d1794c 100755 Binary files a/ZH_TW.zip and b/ZH_TW.zip differ