├── .gitignore ├── .travis.yml ├── Dockerfile ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── README.rst ├── TODO.rst ├── benchmark ├── language_bench.sh └── parser.py ├── docs ├── HISTORY.rst ├── Makefile ├── README.rst ├── TODO.rst ├── _static │ └── custom.css ├── _templates │ └── layout.html ├── conf.py ├── devs │ └── api.rst ├── img │ └── command_line_tools.png ├── index.rst ├── make.bat ├── requirements.txt └── users │ ├── examples.rst │ ├── features.rst │ ├── install.rst │ ├── install_osx.rst │ └── usage.rst ├── img ├── alice.gif ├── helloworld.gif └── helloworld.png ├── requirements.txt ├── setup.cfg ├── setup.py ├── test_requirements.txt ├── texts ├── alice.txt ├── bible.txt ├── text_holmes.txt └── text_monte_cristo.txt ├── translate ├── __init__.py ├── __main__.py ├── __version__.py ├── coroutines.py ├── etc │ └── supported_translations.json ├── languages.py ├── tests │ ├── __init__.py │ ├── test_languages.py │ └── test_translator.py └── translator.py └── version.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source {{{ 2 | *.com 3 | *.class 4 | *.dll 5 | *.exe 6 | *.o 7 | *.so 8 | *.pyc 9 | *.pyo 10 | # }}} 11 | 12 | # Packages {{{ 13 | # it's better to unpack these files and commit the raw source 14 | # git has its own built in compression methods 15 | *.7z 16 | *.dmg 17 | *.gz 18 | *.iso 19 | *.jar 20 | *.rar 21 | *.tar 22 | *.tar.gz 23 | *.zip 24 | # }}} 25 | 26 | # Logs and databases # {{{ 27 | *.log 28 | *.sql 29 | *.sqlite 30 | *.key 31 | benchmark/*.txt 32 | # }}} 33 | 34 | # OS generated files/folders {{{ 35 | .DS_Store 36 | .DS_Store? 37 | ._* 38 | .Spotlight-V100 39 | .Trashes 40 | ehthumbs.db 41 | Thumbs.db 42 | Icon* 43 | # }}} 44 | 45 | # Repository specific files {{{ 46 | .idea/** 47 | venv/** 48 | # }}} 49 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - '3.4' 4 | - '3.3' 5 | - '2.7' 6 | - 'pypy' 7 | - 'pypy3' 8 | install: 9 | - pip install -r requirements.txt 10 | - pip install -r test_requirements.txt 11 | - pip install -e . 12 | script: nosetests 13 | deploy: 14 | provider: pypi 15 | user: jjangsangy 16 | password: 17 | secure: O8T+PYUPg6HoOuK1GN84qGhdxu4nCsseweby4qPz5MXWrVIvqOp4fLIA4MK6d/apD0PhJnjBiMFCkK4GlSqCg2NK7wivTb0O/HuCJ/Zcz4MvxHYARgryDgGfgS2MTm3QBkPXrflLokJrRCO3HMoCMJGpvaZVcq5pVDTmJ/r5CYU= 18 | on: 19 | tags: true 20 | repo: jjangsangy/py-translate 21 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM buildpack-deps:jessie 2 | 3 | # remove several traces of debian python 4 | RUN apt-get purge -y python.* 5 | 6 | # http://bugs.python.org/issue19846 7 | # > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. 8 | ENV LANG C.UTF-8 9 | 10 | # gpg: key F73C700D: public key "Larry Hastings " imported 11 | RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 97FC712E4C024BBEA48A61ED3A5CA953F73C700D 12 | 13 | ENV PYTHON_VERSION 3.5.0 14 | ENV RELEASE_VERSION b4 15 | 16 | # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" 17 | ENV PYTHON_PIP_VERSION 7.1.0 18 | 19 | RUN set -x \ 20 | && mkdir -p /usr/src/python \ 21 | && curl -SL "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION$RELEASE_VERSION.tar.xz" -o python.tar.xz \ 22 | && curl -SL "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION$RELEASE_VERSION.tar.xz.asc" -o python.tar.xz.asc \ 23 | && gpg --verify python.tar.xz.asc \ 24 | && tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ 25 | && rm python.tar.xz* \ 26 | && cd /usr/src/python \ 27 | && ./configure --enable-shared --enable-unicode=ucs4 \ 28 | && make -j$(nproc) \ 29 | && make install \ 30 | && ldconfig \ 31 | && pip3 install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \ 32 | && find /usr/local \ 33 | \( -type d -a -name test -o -name tests \) \ 34 | -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ 35 | -exec rm -rf '{}' + \ 36 | && rm -rf /usr/src/python 37 | 38 | # make some useful symlinks that are expected to exist 39 | RUN cd /usr/local/bin \ 40 | && ln -s easy_install-3.4 easy_install \ 41 | && ln -s idle3 idle \ 42 | && ln -s pydoc3 pydoc \ 43 | && ln -s python3 python \ 44 | && ln -s python-config3 python-config 45 | 46 | CMD ["python3"] 47 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Release History 3 | ================= 4 | 5 | 1.0.2 (2015-01-02) 6 | ------------------ 7 | - Happy New Year 8 | - Created quick benchmarking suite 9 | - Optimized thread utilization 10 | - Bug fixes and better IO performance 11 | 12 | 1.0.1 (2014-12-30) 13 | ------------------ 14 | - More efficient task processing using `map` over `submit`. 15 | - Seperated IO in coroutine exception blocks. 16 | - Bug Fixes and Improvements. 17 | 18 | 1.0.0 (2014-12-18) 19 | ------------------ 20 | - Bug fix with lines longer than 1000 chars 21 | - Fixed another unicode bug 22 | - Improved Python 2/3 Compatability 23 | - Implemented text transliteration where available 24 | - Implemented simple File IO 25 | - Better utilization of thread pools using futures module. 26 | - Vendorized dependencies 27 | - Swapped transport API from urllib2 with Requests 28 | - SSL/TLS integration for secure web requests 29 | 30 | 31 | 0.2.3 (2014-12-08) 32 | ------------------- 33 | - Bug fix with double output 34 | 35 | 36 | 0.2.2 (2014-12-07) 37 | ------------------- 38 | 39 | - Bug fixes 40 | - Decreased package size 41 | - Split `translator.py` into two seperate modules 42 | 43 | 44 | 0.2.1 (2014-12-04) 45 | ------------------ 46 | - Added Output Buffer Streaming 47 | - Utilized Cooperative Multitasking for Coroutines 48 | - Updated Documentation on API 49 | 50 | 0.2.0 (2014-11-30) 51 | ------------------ 52 | 53 | - Bug fixes 54 | - Implmented concurrency based on Asyncronous threads and coroutines 55 | - Up to 10x performance speedup 56 | 57 | 0.1.6 (2014-11-30) 58 | ------------------- 59 | 60 | - Bug Fixes 61 | - Re-implmenenting concurrency models 62 | - Python 3 is now the base implemntation 63 | 64 | 65 | 0.1.5 (2014-07-18) 66 | ------------------- 67 | 68 | - Language Code Generator Fix 69 | 70 | 0.1.4 (2014-07-05) 71 | -------------------- 72 | 73 | - General Bug Fixes 74 | - Speed Improvements 75 | - Length of multibyte characters correctly represented by spooler 76 | - Better support for utf-8. 77 | 78 | 0.1.3 (2014-04-07) 79 | ------------------- 80 | 81 | - Implemented language discovery arg 82 | - Bug Fixes 83 | 84 | 0.1.2 (2014-04-04) 85 | ------------------- 86 | 87 | - Documentation reorganization 88 | 89 | **Bug Fixes** 90 | 91 | - Fixed unicode encode/decode errors 92 | 93 | 0.1.1 (2014-04-03) 94 | -------------------- 95 | 96 | - PyPy-c v2.2 now support 97 | 98 | **Bug Fixes** 99 | 100 | - Quick fix PyPI distribution (huge package sizes) 101 | - MANIFEST.in now does it job 102 | - Assorted fixes with methods and scope 103 | 104 | 0.1.0 (2014-04-02) 105 | -------------------- 106 | 107 | - GTranslate is taken on PyPI. 108 | - Name changed to py-translate 109 | - Distributed through PyPI and Wheel 110 | - More documentation and autoparsing for module functions 111 | - Separated into logical modules in a package rather than one executable `__main__.py` 112 | 113 | 0.0.0 (2014-03-31) 114 | -------------------- 115 | 116 | - Support for Python 2.7 and 3.x 117 | - Sphinx Documentation hosted 118 | - Travis CI build passed! 119 | - Source released on Github 120 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2014 Sang Han 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include .travis.yml 3 | include requirements.txt 4 | include test_requirements.txt 5 | include translate/etc/supported_translations.json 6 | include version.py 7 | include HISTORY.rst 8 | include README.rst 9 | 10 | recursive-include translate *.py 11 | recursive-exclude texts * 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | PROJECT := py-translate 3 | VERSION := 2 4 | PYTHON := $(shell which python$(VERSION)) 5 | OSNAME := $(shell uname -s) 6 | ARCH := $(shell uname -m) 7 | 8 | PIP := pip$(VERSION) 9 | APP := py-translate 10 | TEST := test 11 | DOCKER_TAG := jjangsangy/python3:3.5.0b4 12 | 13 | INSTALL := Miniconda$(subst 2,,$(VERSION))-latest-$(subst Darwin,MacOSX,$(OSNAME))-$(ARCH).sh 14 | URL := http://repo.continuum.io/miniconda/${INSTALL} 15 | CONDA := miniconda/bin/conda 16 | IPYTHON := miniconda/bin/ipython 17 | CACHE := cache 18 | 19 | BIN := node_modules/.bin 20 | NPM := $(BIN)/npm 21 | BOWER := $(BIN)/bower 22 | NVM := https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh 23 | NVM_DIR := $(PWD)/nvm 24 | LOAD := ./$(CACHE)/$(INSTALL) 25 | 26 | .PHONY: all 27 | all: install 28 | 29 | .PHONY: miniconda 30 | miniconda: $(CONDA) 31 | $(CONDA) update conda 32 | 33 | $(CONDA): 34 | @echo $(LAOD) 35 | @echo "installing Miniconda" 36 | @if [ -x $(which curl) ]; then \ 37 | curl -O $(URL) -o $(LOAD); \ 38 | elif [ -x $(which wget) ]; then \ 39 | wget $(URL) -o $(LOAD); \ 40 | fi 41 | @if [ -r miniconda ]; then rm -rf miniconda; fi 42 | @bash $(INSTALL) -b -p miniconda 43 | $(CONDA) create -n venv python=$(VERSION)* 44 | 45 | .PHONY: help 46 | help: 47 | @echo " Usage: \`make '" 48 | @echo " =======================" 49 | @echo " npm install npm and nodejs" 50 | @echo " bower install bower and javascript" 51 | @echo " serve serve ipython notebook on port 8000" 52 | @echo " clean remove build files" 53 | @echo " miniconda boostrap anacondas python" 54 | @echo 55 | @echo 56 | 57 | .PHONY: ipython 58 | ipython: $(CONDA) 59 | @echo "Installing IPython" 60 | 61 | $(IPYTHON): 62 | @echo "Installing Required Packages" 63 | $(CONDA) install -y anaconda 64 | 65 | npm: $(NVM_DIR)/nvm.sh 66 | @echo "Installing NodeJS Packages" 67 | @test -d $(BIN) || mkdir -p $(BIN) 68 | npm install . 69 | 70 | $(NVM_DIR)/nvm.sh: 71 | @echo "Installing NVM" 72 | @git clone https://github.com/creationix/nvm.git 73 | source nvm/nvm.sh && nvm install stable && nvm use stable && npm install . 74 | 75 | .PHONY: bower 76 | bower: npm 77 | @echo "Installing Javascript Packages" 78 | @$(NPM) install --loglevel silent . 79 | 80 | bower.json: bower 81 | $(bower) init 82 | @$(BOWER) install 83 | 84 | .PHONY: install 85 | install: miniconda npm bower 86 | @echo "Installing Packages" 87 | 88 | .PHONY: serve 89 | serve: install 90 | $(IPYTHON)/ipython nbconvert --serve Qadium.ipynb 91 | 92 | .PHONY: clean 93 | clean: 94 | rm -rf node_modules 95 | rm -rf venv 96 | rm -rf .DS_Store 97 | rm -rf miniconda 98 | rm -rf nvm 99 | 100 | venv: venv/bin/activate 101 | venv/bin/activate: requirements.txt 102 | test -d venv || virtualenv --python=$(PYTHON) venv 103 | source venv/bin/activate; \ 104 | $(PIP) install --upgrade pip setuptools wheel; \ 105 | $(PIP) install -r requirements.txt --upgrade 106 | touch venv/bin/activate 107 | 108 | .PHONY: clean wheel publish docker bash daemon 109 | 110 | all: 111 | $(PYTHON) setup.py build 112 | 113 | build: venv 114 | source env/bin/activate; \ 115 | $(PYTHON) setup.py install 116 | 117 | install: 118 | $(PIP) install -e . 119 | 120 | test: build 121 | source venv/bin/activate; \ 122 | $(PIP) install -r test_requirements.txt --upgrade; \ 123 | $(PYTHON) setup.py $(TEST) 124 | 125 | wheel: 126 | $(PYTHON) setup.py bdist_wheel 127 | 128 | publish: 129 | $(PYTHON) setup.py build nosetests 130 | $(PYTHON) setup.py sdist upload -r pypi 131 | $(PYTHON) setup.py bdist_wheel upload -r pypi 132 | 133 | clean: 134 | rm -rf $(APP)/*.pyc 135 | rm -rf __pycache__ 136 | rm -rf $(APP)/__pycache__ 137 | rm -rf build 138 | rm -rf *egg-info 139 | rm -rf dist 140 | rm -rf venv 141 | if [ -f "$(SCRIPT)" ]; then rm "$(SCRIPT)"; fi 142 | 143 | 144 | docker: 145 | docker build -t $(DOCKER_TAG) . 146 | bash: 147 | docker run -i -t $(DOCKER_TAG) /bin/bash -l 148 | daemon: 149 | docker run -d -P $(DOCKER_TAG) 150 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | py-translate (Deprecated) 2 | ========================= 3 | 4 | > This library has been deprecated due to changes in Google Terms of Agreement. 5 | > Please use the [Google Cloud Translation API](https://cloud.google.com/translate/docs/) 6 | 7 | [![Documentation](https://readthedocs.org/projects/py-translate/badge/?version=master)](https://readthedocs.org/projects/py-translate/?badge=master) [![github](https://badge.fury.io/gh/jjangsangy%2Fpy-translate.svg)](http://badge.fury.io/gh/jjangsangy%2Fpy-translate) [![travis](https://travis-ci.org/jjangsangy/py-translate.svg?branch=master)](https://travis-ci.org/jjangsangy/py-translate) [![pypi](https://badge.fury.io/py/py-translate.svg)](http://badge.fury.io/py/py-translate) [![Wheel](https://pypip.in/wheel/py-translate/badge.svg)](https://pypi.python.org/pypi/py-translate/) 8 | 9 | A Translation Tool for Humans 10 | 11 | ![Translate Lewis Carroll: Alice in Wonderland][alice] 12 | 13 | ------------------------------------------------ 14 | 15 | The end goal is a simple application for translating text in the terminal. 16 | Text can be generated interactively or programmatically in the 17 | shell environment. Through command line arguments, file descriptors or 18 | pipes generating translated output that can be piped to a file or 19 | displayed on the terminal. 20 | 21 | Features 22 | ---------- 23 | 24 | - Made for Python 3 but still works on Python 2 25 | - Fast and easy to install, easy to use 26 | - Supports translation from any language 27 | - Highly composable interface, the power of Unix pipes and filters. 28 | - Simple API and documentation 29 | 30 | Installation 31 | ------------ 32 | 33 | ### From PyPI with `pip` 34 | 35 | ```sh 36 | $ pip install py-translate 37 | ``` 38 | 39 | ### From Source at Github 40 | 41 | - Clone the repository 42 | 43 | ```sh 44 | $ git clone https://github.com/jjangsangy/py-translate.git && cd py-translate 45 | ``` 46 | 47 | - Install with setup.py 48 | 49 | ```sh 50 | $ python setup.py install 51 | ``` 52 | 53 | ### If all else fails use `sudo`, but only if you must 54 | 55 | ```sh 56 | $ sudo python setup.py install 57 | ``` 58 | 59 | ## Usage 60 | 61 | ### `translate [--flags] [source] dest` 62 | 63 | ### Arguments 64 | 65 | | **Positional** | | 66 | |--------------------|-------------------------------------------------------| 67 | | dest | Destination language code | 68 | | source | Source language code | 69 | | **Optional** | | 70 | | -h,--help | Show this help message and exit | 71 | | -v, --version | Show program’s version number and exit | 72 | | -l,--list _[code]_ | Enumerate the name of country and language code pair. | 73 | | | [_Optionally specify output language format_] | 74 | | --translit | Print out the transliteration of the text | 75 | 76 | 77 | Examples 78 | -------- 79 | 80 | Hello World from English to Traditional Chinese 81 | 82 | ```sh 83 | $ translate en zh-TW <<< 'Hello World!' 84 | 你好世界! 85 | 86 | ``` 87 | 88 | ![Hello World][hello] 89 | 90 | - Just as easily specify a source language by providing it as first argument 91 | 92 | ```sh 93 | # Translate Hello from French to English 94 | $ translate fr en <<< 'Bonjour, comment allez-vous!' 95 | Hello, how are you? 96 | ``` 97 | 98 | ### Smart Language Detection 99 | Omitting the source language will try to detect it based on the text content 100 | 101 | ```sh 102 | $ translate fr <<< 'I think therefore I am' 103 | Je pense donc je suis 104 | ``` 105 | 106 | ### Romanified Transliteration 107 | 108 | ```sh 109 | $ translate --translit en ko <<< 'Want to fight!' 110 | ssaugo sip-eo! 111 | 112 | $ translate --translit en zh-TW <<< 'Kidding, we should be friends' 113 | Kāiwánxiào, wǒmen yīnggāi shì péngyǒu 114 | ``` 115 | 116 | ### Redirect from File 117 | 118 | ```sh 119 | $ translate zh-TW < 'alice.txt' 120 | 121 | 阿麗思道:「你不是說你要告訴你的歷史嗎?告訴我你為甚麼恨—那個—那些—C和D,」 122 | 她末了兩個字母輕輕兒地說的,怕回來又得罪了牠。 123 | 124 | 那老鼠對著阿麗思嘆了一口氣道,「唉﹗我的身世說來可真是又長又苦又委屈呀—」 125 | 126 | 阿麗思聽了,瞧著那老鼠的尾巴說,「你這尾是曲啊﹗可是為甚麼又叫它苦呢﹗」 127 | 她就一頭聽著那老鼠說話,一頭在在心上納悶,所以她聽的那老鼠講的「尾曲」 128 | 的歷史是差不多像這個樣了的 129 | .... 130 | ``` 131 | 132 | ### Chaining together Pipes 133 | 134 | ```sh 135 | # Multiple Chaining 136 | $ echo 'What is love?' | translate en zh-TW | translate zh-TW ko | translate ko fr | translate fr en 137 | What is love? 138 | ``` 139 | 140 | ### Be Creative! 141 | 142 | ```sh 143 | # Grocery List 144 | $ cat << BUY | translate ko 145 | Celery 146 | Milk 147 | Eggs 148 | Bread 149 | Cereal 150 | BUY 151 | 152 | 셀러리 153 | 우유 154 | 달걀 155 | 빵 156 | 시리얼 157 | ``` 158 | 159 | Support 160 | -------- 161 | 162 | Here’s a list of Python platforms that are officially supported. 163 | 164 | - Python 3.4 165 | - Python 3.3 166 | - Python 3.2 167 | - Python 2.7 168 | - Python 2.6 169 | - PyPy 2 (Latest) 170 | - PyPy 3 (latest) 171 | 172 | Documentation 173 | ------------- 174 | 175 | Find the latest documentation http://pythonhosted.org/py-translate/ 176 | 177 | 178 | Contribute 179 | ------------ 180 | 181 | 1. Fork us on [Github](https://github.com/jjangsangy/py-translate). 182 | 183 | 2. Find a bug? Implemented a new feature? Send a pull request to get it merged and published. 184 | 185 | 3. Feel free to send an e-mail to the code maintainer for questions or help regarding the codebase. 186 | [jjangsangy@gmail.com](jjangsangy@gmail.com) 187 | 188 | 189 | [alice]: https://raw.githubusercontent.com/jjangsangy/py-translate/master/img/alice.gif 190 | 191 | [hello]: https://raw.githubusercontent.com/jjangsangy/py-translate/master/img/helloworld.gif 192 | 193 | [Documentation]: https://readthedocs.org/projects/py-translate/badge/?version=master 194 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | py-translate 2 | ============ 3 | 4 | |Documentation| |github| |travis| |pypi| |Wheel| 5 | 6 | A Translation Tool for Humans 7 | 8 | .. figure:: https://raw.githubusercontent.com/jjangsangy/py-translate/master/img/alice.gif 9 | :alt: Translate Lewis Carroll: Alice in Wonderland 10 | 11 | Translate Lewis Carroll: Alice in Wonderland 12 | 13 | -------------- 14 | 15 | The end goal is a simple application for translating text in the 16 | terminal. Text can be generated interactively or programmatically in the 17 | shell environment. Through command line arguments, file descriptors or 18 | pipes generating translated output that can be piped to a file or 19 | displayed on the terminal. 20 | 21 | Features 22 | -------- 23 | 24 | - Made for Python 3 but still works on Python 2 25 | - Fast and easy to install, easy to use 26 | - Supports translation from any language 27 | - Highly composable interface, the power of Unix pipes and filters. 28 | - Simple API and documentation 29 | 30 | Installation 31 | ------------ 32 | 33 | From PyPI with pip (easy) 34 | ~~~~~~~~~~~~~~~~~~~~~~~~~ 35 | 36 | .. code:: sh 37 | 38 | $ pip install py-translate 39 | 40 | From Source at Github 41 | ~~~~~~~~~~~~~~~~~~~~~ 42 | 43 | - Clone the repository 44 | 45 | .. code:: sh 46 | 47 | $ git clone https://github.com/jjangsangy/py-translate.git 48 | 49 | - Install with setup.py 50 | 51 | .. code:: sh 52 | 53 | $ python setup.py install 54 | 55 | Usage 56 | ----- 57 | 58 | ``translate [--flags] [source] dest`` 59 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | 61 | Arguments 62 | ~~~~~~~~~ 63 | 64 | +------------------+-------------------------------------------------------+ 65 | | **Positional** | | 66 | +==================+=======================================================+ 67 | | dest | Destination language code | 68 | +------------------+-------------------------------------------------------+ 69 | | source | Source language code | 70 | +------------------+-------------------------------------------------------+ 71 | | **Optional** | | 72 | +------------------+-------------------------------------------------------+ 73 | | -h,--help | Show this help message and exit | 74 | +------------------+-------------------------------------------------------+ 75 | | -v, --version | Show program’s version number and exit | 76 | +------------------+-------------------------------------------------------+ 77 | | -l,--list [code] | Enumerate the name of country and language code pair. | 78 | +------------------+-------------------------------------------------------+ 79 | | | [ Optionally specify output language format ] | 80 | +------------------+-------------------------------------------------------+ 81 | | --translit | Print out the transliteration of the text | 82 | +------------------+-------------------------------------------------------+ 83 | 84 | Examples 85 | -------- 86 | 87 | Hello World from English to Traditional Chinese 88 | 89 | .. code:: sh 90 | 91 | $ translate en zh-TW <<< 'Hello World!' 92 | 你好世界! 93 | 94 | .. figure:: https://raw.githubusercontent.com/jjangsangy/py-translate/master/img/helloworld.gif 95 | :alt: Hello World 96 | 97 | Hello World 98 | 99 | - Just as easily specify a source language by providing it as first 100 | argument 101 | 102 | .. code:: sh 103 | 104 | # Translate Hello from French to English 105 | $ translate fr en <<< 'Bonjour, comment allez-vous!' 106 | Hello, how are you? 107 | 108 | Smart Language Detection 109 | ~~~~~~~~~~~~~~~~~~~~~~~~ 110 | 111 | Omitting the source language will try to detect it based on the text 112 | content 113 | 114 | .. code:: sh 115 | 116 | $ translate fr <<< 'I think therefore I am' 117 | Je pense donc je suis 118 | 119 | Romanified Transliteration 120 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 121 | 122 | .. code:: sh 123 | 124 | $ translate --translit en ko <<< 'Want to fight!' 125 | ssaugo sip-eo! 126 | 127 | $ translate --translit en zh-TW <<< 'Kidding, we should be friends' 128 | Kāiwánxiào, wǒmen yīnggāi shì péngyǒu 129 | 130 | Redirect from File 131 | ~~~~~~~~~~~~~~~~~~ 132 | 133 | .. code:: sh 134 | 135 | $ translate zh-TW < 'alice.txt' 136 | 137 | 阿麗思道:「你不是說你要告訴你的歷史嗎?告訴我你為甚麼恨—那個—那些—C和D,」 138 | 她末了兩個字母輕輕兒地說的,怕回來又得罪了牠。 139 | 140 | 那老鼠對著阿麗思嘆了一口氣道,「唉﹗我的身世說來可真是又長又苦又委屈呀—」 141 | 142 | 阿麗思聽了,瞧著那老鼠的尾巴說,「你這尾是曲啊﹗可是為甚麼又叫它苦呢﹗」 143 | 她就一頭聽著那老鼠說話,一頭在在心上納悶,所以她聽的那老鼠講的「尾曲」 144 | 的歷史是差不多像這個樣了的 145 | .... 146 | 147 | Chaining together Pipes 148 | ~~~~~~~~~~~~~~~~~~~~~~~ 149 | 150 | .. code:: sh 151 | 152 | # Multiple Chaining 153 | $ echo 'What is love?' | translate en zh-TW | translate zh-TW ko | translate ko fr | translate fr en 154 | What is love? 155 | 156 | Be Creative! 157 | ~~~~~~~~~~~~ 158 | 159 | .. code:: sh 160 | 161 | # Grocery List 162 | $ cat << BUY | translate ko 163 | Celery 164 | Milk 165 | Eggs 166 | Bread 167 | Cereal 168 | BUY 169 | 170 | 셀러리 171 | 우유 172 | 달걀 173 | 빵 174 | 시리얼 175 | 176 | Support 177 | ------- 178 | 179 | Here’s a list of Python platforms that are officially supported. 180 | 181 | - Python 3.4 182 | - Python 3.3 183 | - Python 3.2 184 | - Python 2.7 185 | - Python 2.6 186 | - PyPy 2 (Latest) 187 | - PyPy 3 (latest) 188 | 189 | Documentation 190 | ------------- 191 | 192 | Find the latest documentation http://pythonhosted.org/py-translate/ 193 | 194 | Contribute 195 | ---------- 196 | 197 | 1. Fork us on `Github `__. 198 | 199 | 2. Find a bug? Implemented a new feature? Send a pull request to get it 200 | merged and published. 201 | 202 | 3. Feel free to send an e-mail to the code maintainer for questions or 203 | help regarding the codebase. 204 | `jjangsangy@gmail.com `__ 205 | 206 | 207 | .. |Documentation| image:: https://readthedocs.org/projects/py-translate/badge/?version=master 208 | :target: https://readthedocs.org/projects/py-translate/?badge=master 209 | 210 | .. |github| image:: https://badge.fury.io/gh/jjangsangy%2Fpy-translate.svg 211 | :target: http://badge.fury.io/gh/jjangsangy%2Fpy-translate 212 | 213 | .. |travis| image:: https://travis-ci.org/jjangsangy/py-translate.svg?branch=master 214 | :target: https://travis-ci.org/jjangsangy/py-translate 215 | 216 | .. |pypi| image:: https://badge.fury.io/py/py-translate.svg 217 | :target: http://badge.fury.io/py/py-translate 218 | 219 | .. |Wheel| image:: https://pypip.in/wheel/py-translate/badge.svg 220 | :target: https://pypi.python.org/pypi/py-translate/ 221 | -------------------------------------------------------------------------------- /TODO.rst: -------------------------------------------------------------------------------- 1 | .. :todo: 2 | 3 | ======== 4 | TODO 5 | ======== 6 | 7 | .. hlist:: 8 | :columns: 2 9 | 10 | - Raise exception if nothing is entered into stdin 11 | - Write documentation for intro 12 | - Implement Unit Testing framework with nose 13 | - Use twine for publishing to PyPI 14 | -------------------------------------------------------------------------------- /benchmark/language_bench.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ============================================================================== 3 | usage () { cat <<- DOCUMENT 4 | 5 | AUTHOR: Sang Han 6 | 7 | Benchmark py-translation 8 | 9 | USAGE: 10 | 11 | ./language_bench.sh [-h] 12 | 13 | OPTIONAL ARGUMENTS: 14 | 15 | [-h]: Prints out this help message and exit 16 | 17 | DOCUMENT 18 | 19 | return 0 20 | } 21 | 22 | 23 | # =============================================================================== 24 | # Language Codes 25 | # =============================================================================== 26 | 27 | declare -a codes=( 28 | 'af' 'ar' 'az' 'be' 'bg' 'bn' 'bs' 'ca' 'ceb' 29 | 'cs' 'cy' 'da' 'de' 'el' 'en' 'eo' 'es' 'et' 30 | 'eu' 'fa' 'fi' 'fr' 'ga' 'gl' 'gu' 'hi' 'hmn' 31 | 'hr' 'ht' 'hu' 'id' 'is' 'it' 'iw' 'ja' 'jw' 32 | 'ka' 'km' 'kn' 'ko' 'la' 'lo' 'lt' 'lv' 'mk' 33 | 'mr' 'ms' 'mt' 'nl' 'no' 'pl' 'pt' 'ro' 'ru' 34 | 'sk' 'sl' 'sq' 'sr' 'sv' 'sw' 'ta' 'te' 'th' 35 | 'tl' 'tr' 'uk' 'ur' 'vi' 'yi' 'zh' 'zh-TW' 36 | ) 37 | 38 | # =============================================================================== 39 | # Option Parser 40 | # =============================================================================== 41 | while getopts ":h" OPTION; do 42 | case ${OPTION} in 43 | h) usage 44 | exit 0 45 | ;; 46 | esac 47 | done 48 | shift $((OPTIND-1)) 49 | 50 | 51 | # =============================================================================== 52 | # Main 53 | # =============================================================================== 54 | function main() 55 | { 56 | local input="../texts/alice.txt" 57 | local output="raw.txt" 58 | local source="en" 59 | 60 | for target in "${codes[@]}"; do 61 | { 62 | printf "%s" "${target}" >> "${output}" 63 | { 64 | time translate "${source}" "${target}" < "${input}" 65 | } 2> >(grep 'real' | sed 's/real//' | tee -a "${output}") 66 | 67 | } 68 | 69 | done 70 | } 71 | 72 | # =============================================================================== 73 | # Entry Point 74 | # =============================================================================== 75 | if [ "${0}" = "${BASH_SOURCE}" ]; then 76 | main "$@" 77 | fi 78 | -------------------------------------------------------------------------------- /benchmark/parser.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- # 2 | 3 | from __future__ import print_function 4 | 5 | from numpy import mean, std 6 | 7 | def reader(benchmark): 8 | 9 | with open(benchmark, 'rt') as bench: 10 | raw = bench.read() 11 | 12 | return [(data.split('\t')) for data in raw.split('\n')][0:-1] 13 | 14 | 15 | def parsed(): 16 | init = dict() 17 | values = reader('raw.txt') 18 | mapping = init.fromkeys([key for key, value in values], ()) 19 | 20 | for value in values: 21 | 22 | [[mins], [secs,_]] = [i.split('s') for i in value[1].split('m')] 23 | [(time), (keys) ] = [float(mins) * 60 + float(secs), value[0]] 24 | 25 | mapping[keys] += (time,) 26 | 27 | return mapping 28 | 29 | 30 | def main(): 31 | bench = parsed() 32 | flat = [x for l in bench.values() for x in l] 33 | fmt = '{}\t{:2.2f}s\t ÷ {}\t{:2.2f}s' 34 | 35 | print("Code\tSum\t Runs\tMean") 36 | for keys,value in sorted(bench.items()): 37 | 38 | print(fmt.format( 39 | keys, 40 | sum(value), 41 | len(value), 42 | mean(value)) 43 | ) 44 | 45 | print() 46 | print("Total Time:\t{:2.2f}s".format(sum(flat))) 47 | print("Sample Size:\t{}".format(len(flat))) 48 | print("Average:\t{:2.2f}s".format(mean(flat))) 49 | print("Standard Dev:\t{:2.2f}s".format(std(flat))) 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /docs/HISTORY.rst: -------------------------------------------------------------------------------- 1 | ../HISTORY.rst -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/py-translate.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/py-translate.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/py-translate" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/py-translate" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/README.rst: -------------------------------------------------------------------------------- 1 | ../README.rst -------------------------------------------------------------------------------- /docs/TODO.rst: -------------------------------------------------------------------------------- 1 | ../TODO.rst -------------------------------------------------------------------------------- /docs/_static/custom.css: -------------------------------------------------------------------------------- 1 | .table-hover { 2 | width: 50% 3 | } 4 | -------------------------------------------------------------------------------- /docs/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html"%} 2 | 3 | {% block header %} 4 | {{ super() }} 5 | 11 | 18 | {% endblock %} 19 | 20 | {# Custom CSS overrides #} 21 | {% set bootswatch_css_custom = ['_static/custom.css'] %} 22 | 23 | {% block navbarextra %} 24 | {%- block sidebar1 %}{{ bsidebar() }}{% endblock %} 25 | {% endblock %} 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # py-translate documentation build configuration file, created by 5 | # sphinx-quickstart on Wed Mar 26 13:21:22 2014. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | 19 | # If extensions (or modules to document with autodoc) are in another directory, 20 | # add these directories to sys.path here. If the directory is relative to the 21 | # documentation root, use os.path.abspath to make it absolute, like shown here. 22 | sys.path.insert(0, os.path.abspath('..')) 23 | 24 | import translate 25 | 26 | import sphinx_bootstrap_theme 27 | 28 | from translate import __version__, __build__, __title__, __copyright__ 29 | 30 | # -- General configuration ------------------------------------------------ 31 | 32 | # If your documentation needs a minimal Sphinx version, state it here. 33 | #needs_sphinx = '1.0' 34 | 35 | # Add any Sphinx extension module names here, as strings. They can be 36 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 37 | # ones. 38 | extensions = [ 39 | 'sphinx.ext.autodoc', 40 | 'sphinx.ext.doctest', 41 | 'sphinx.ext.intersphinx', 42 | 'sphinx.ext.todo', 43 | 'sphinx.ext.coverage', 44 | 'sphinx.ext.mathjax', 45 | 'sphinx.ext.ifconfig', 46 | 'sphinx.ext.viewcode', 47 | ] 48 | 49 | todo_include_todos = True 50 | 51 | # Add any paths that contain templates here, relative to this directory. 52 | templates_path = ['_templates'] 53 | 54 | # The suffix of source filenames. 55 | source_suffix = '.rst' 56 | 57 | # The encoding of source files. 58 | #source_encoding = 'utf-8-sig' 59 | 60 | # The master toctree document. 61 | master_doc = 'index' 62 | 63 | # General information about the project. 64 | project = __title__ 65 | copyright = __copyright__ 66 | 67 | # The version info for the project you're documenting, acts as replacement for 68 | # |version| and |release|, also used in various other places throughout the 69 | # built documents. 70 | # 71 | # The short X.Y version. 72 | version = __version__ 73 | # The full version, including alpha/beta/rc tags. 74 | release = __version__ + __build__ 75 | 76 | # The language for content autogenerated by Sphinx. Refer to documentation 77 | # for a list of supported languages. 78 | #language = None 79 | 80 | # There are two options for replacing |today|: either, you set today to some 81 | # non-false value, then it is used: 82 | #today = '' 83 | # Else, today_fmt is used as the format for a strftime call. 84 | #today_fmt = '%B %d, %Y' 85 | 86 | # List of patterns, relative to source directory, that match files and 87 | # directories to ignore when looking for source files. 88 | exclude_patterns = ['_build'] 89 | 90 | # The reST default role (used for this markup: `text`) to use for all 91 | # documents. 92 | #default_role = None 93 | 94 | # If true, '()' will be appended to :func: etc. cross-reference text. 95 | #add_function_parentheses = True 96 | 97 | # If true, the current module name will be prepended to all description 98 | # unit titles (such as .. function::). 99 | #add_module_names = True 100 | 101 | # If true, sectionauthor and moduleauthor directives will be shown in the 102 | # output. They are ignored by default. 103 | show_authors = True 104 | 105 | # The name of the Pygments (syntax highlighting) style to use. 106 | pygments_style = 'sphinx' 107 | 108 | # A list of ignored prefixes for module index sorting. 109 | #modindex_common_prefix = [] 110 | 111 | # If true, keep warnings as "system message" paragraphs in the built documents. 112 | #keep_warnings = False 113 | 114 | 115 | # -- Options for HTML output ---------------------------------------------- 116 | 117 | # The theme to use for HTML and HTML Help pages. See the documentation for 118 | # a list of builtin themes. 119 | html_theme = 'bootstrap' 120 | 121 | # Theme options are theme-specific and customize the look and feel of a theme 122 | # further. For a list of options available for each theme, see the 123 | # documentation. 124 | html_theme_options = { 125 | 'navbar_title': "py-translate", 126 | 'navbar_site_name': "Site", 127 | 'globaltoc_depth': 2, 128 | 'globaltoc_includehidden': True, 129 | 'navbar_sidebarrel': True, 130 | 'navbar_class': "navbar", 131 | 'navbar_pagenav': True, 132 | 'navbar_fixed_top': True, 133 | 'source_link_position': "nav", 134 | 'bootswatch_theme': "flatly", 135 | 'bootstrap_version': "3", 136 | } 137 | 138 | html_theme_path = sphinx_bootstrap_theme.get_html_theme_path() 139 | # Add any paths that contain custom themes here, relative to this directory. 140 | 141 | # The name for this set of Sphinx documents. If None, it defaults to 142 | # " v documentation". 143 | #html_title = None 144 | 145 | # A shorter title for the navigation bar. Default is the same as html_title. 146 | #html_short_title = None 147 | 148 | # The name of an image file (relative to this directory) to place at the top 149 | # of the sidebar. 150 | #html_logo = None 151 | 152 | # The name of an image file (within the static path) to use as favicon of the 153 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 154 | # pixels large. 155 | #html_favicon = None 156 | 157 | # Add any paths that contain custom static files (such as style sheets) here, 158 | # relative to this directory. They are copied after the builtin static files, 159 | # so a file named "default.css" will overwrite the builtin "default.css". 160 | html_static_path = ['_static'] 161 | 162 | # Add any extra paths that contain custom files (such as robots.txt or 163 | # .htaccess) here, relative to this directory. These files are copied 164 | # directly to the root of the documentation. 165 | #html_extra_path = [] 166 | 167 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 168 | # using the given strftime format. 169 | #html_last_updated_fmt = '%b %d, %Y' 170 | 171 | # If true, SmartyPants will be used to convert quotes and dashes to 172 | # typographically correct entities. 173 | #html_use_smartypants = True 174 | 175 | # Custom sidebar templates, maps document names to template names. 176 | html_sidebars = {'sidebar': ['localtoc.html', 'sourcelink.html', 'searchbox.html']} 177 | 178 | # Additional templates that should be rendered to pages, maps page names to 179 | # template names. 180 | #html_additional_pages = {} 181 | 182 | # If false, no module index is generated. 183 | #html_domain_indices = True 184 | 185 | # If false, no index is generated. 186 | #html_use_index = True 187 | 188 | # If true, the index is split into individual pages for each letter. 189 | #html_split_index = False 190 | 191 | # If true, links to the reST sources are added to the pages. 192 | html_show_sourcelink = True 193 | 194 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 195 | #html_show_sphinx = True 196 | 197 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 198 | html_show_copyright = True 199 | 200 | # If true, an OpenSearch description file will be output, and all pages will 201 | # contain a tag referring to it. The value of this option must be the 202 | # base URL from which the finished HTML is served. 203 | #html_use_opensearch = '' 204 | 205 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 206 | html_file_suffix = '.html' 207 | 208 | # Output file base name for HTML help builder. 209 | htmlhelp_basename = 'py-translatedoc' 210 | 211 | 212 | # -- Options for LaTeX output --------------------------------------------- 213 | 214 | latex_elements = { 215 | 'inputenc': '', 216 | 'utf8extra': '', 217 | 'preamble': ''' 218 | \\hypersetup{unicode=true} 219 | \\usepackage{CJKutf8} 220 | \\usepackage[utf8]{inputenc} 221 | \\usepackage[T1]{fontenc} 222 | \\AtBeginDocument{\\begin{CJK}{UTF8}{STSong}} 223 | \\AtEndDocument{\end{CJK}} 224 | ''', 225 | } 226 | 227 | # Grouping the document tree into LaTeX files. List of tuples 228 | # (source start file, target name, title, 229 | # author, documentclass [howto, manual, or own class]). 230 | latex_documents = [ 231 | ('index', 'py-translate.tex', 'py-translate Documentation', 232 | 'Sang Han', 'manual'), 233 | ] 234 | 235 | # The name of an image file (relative to this directory) to place at the top of 236 | # the title page. 237 | #latex_logo = None 238 | 239 | # For "manual" documents, if this is true, then toplevel headings are parts, 240 | # not chapters. 241 | #latex_use_parts = False 242 | 243 | # If true, show page references after internal links. 244 | #latex_show_pagerefs = False 245 | 246 | # If true, show URL addresses after external links. 247 | #latex_show_urls = False 248 | 249 | # Documents to append as an appendix to all manuals. 250 | #latex_appendices = [] 251 | 252 | # If false, no module index is generated. 253 | #latex_domain_indices = True 254 | 255 | 256 | # -- Options for manual page output --------------------------------------- 257 | 258 | # One entry per manual page. List of tuples 259 | # (source start file, name, description, authors, manual section). 260 | man_pages = [ 261 | ('index', 'py-translate', 'py-translate Documentation', 262 | ['Sang Han'], 1) 263 | ] 264 | 265 | # If true, show URL addresses after external links. 266 | #man_show_urls = False 267 | 268 | 269 | # -- Options for Texinfo output ------------------------------------------- 270 | 271 | # Grouping the document tree into Texinfo files. List of tuples 272 | # (source start file, target name, title, author, 273 | # dir menu entry, description, category) 274 | texinfo_documents = [ 275 | ('index', 'py-translate', 'py-translate Documentation', 276 | 'Sang Han', 'py-translate', 'One line description of project.', 277 | 'Miscellaneous'), 278 | ] 279 | 280 | # Documents to append as an appendix to all manuals. 281 | #texinfo_appendices = [] 282 | 283 | # If false, no module index is generated. 284 | #texinfo_domain_indices = True 285 | 286 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 287 | #texinfo_show_urls = 'footnote' 288 | 289 | # If true, do not generate a @detailmenu in the "Top" node's menu. 290 | #texinfo_no_detailmenu = False 291 | 292 | 293 | # -- Options for Epub output ---------------------------------------------- 294 | 295 | # Bibliographic Dublin Core info. 296 | epub_title = 'py-translate' 297 | epub_author = 'Sang Han' 298 | epub_publisher = 'Sang Han' 299 | epub_copyright = '2014, Sang Han' 300 | 301 | # The basename for the epub file. It defaults to the project name. 302 | #epub_basename = 'py-translate' 303 | 304 | # The HTML theme for the epub output. Since the default themes are not optimized 305 | # for small screen space, using the same theme for HTML and epub output is 306 | # usually not wise. This defaults to 'epub', a theme designed to save visual 307 | # space. 308 | #epub_theme = 'epub' 309 | 310 | # The language of the text. It defaults to the language option 311 | # or en if the language is not set. 312 | #epub_language = '' 313 | 314 | # The scheme of the identifier. Typical schemes are ISBN or URL. 315 | #epub_scheme = '' 316 | 317 | # The unique identifier of the text. This can be a ISBN number 318 | # or the project homepage. 319 | #epub_identifier = '' 320 | 321 | # A unique identification for the text. 322 | #epub_uid = '' 323 | 324 | # A tuple containing the cover image and cover page html template filenames. 325 | #epub_cover = () 326 | 327 | # A sequence of (type, uri, title) tuples for the guide element of content.opf. 328 | #epub_guide = () 329 | 330 | # HTML files that should be inserted before the pages created by sphinx. 331 | # The format is a list of tuples containing the path and title. 332 | #epub_pre_files = [] 333 | 334 | # HTML files shat should be inserted after the pages created by sphinx. 335 | # The format is a list of tuples containing the path and title. 336 | #epub_post_files = [] 337 | 338 | # A list of files that should not be packed into the epub file. 339 | epub_exclude_files = ['search.html'] 340 | 341 | # The depth of the table of contents in toc.ncx. 342 | #epub_tocdepth = 3 343 | 344 | # Allow duplicate toc entries. 345 | #epub_tocdup = True 346 | 347 | # Choose between 'default' and 'includehidden'. 348 | #epub_tocscope = 'default' 349 | 350 | # Fix unsupported image types using the PIL. 351 | #epub_fix_images = False 352 | 353 | # Scale large images. 354 | #epub_max_image_width = 0 355 | 356 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 357 | #epub_show_urls = 'inline' 358 | 359 | # If false, no index is generated. 360 | #epub_use_index = True 361 | -------------------------------------------------------------------------------- /docs/devs/api.rst: -------------------------------------------------------------------------------- 1 | .. _api: 2 | 3 | Python API 4 | ============= 5 | 6 | .. codeauthor:: Sang Han 7 | 8 | Translator Co-Routine 9 | ----------------------- 10 | 11 | .. autofunction:: translate.translator 12 | .. autofunction:: translate.coroutine 13 | 14 | HTTP Delegation 15 | ---------------- 16 | 17 | .. autofunction:: translate.push_url 18 | 19 | Stream Caching 20 | ---------------- 21 | 22 | .. autofunction:: translate.source 23 | .. autofunction:: translate.spool 24 | .. autofunction:: translate.set_task 25 | .. autofunction:: translate.write_stream 26 | .. autofunction:: translate.accumulator 27 | 28 | 29 | Multitasking 30 | ------------- 31 | 32 | .. autofunction:: translate.set_task 33 | 34 | Writer 35 | ------- 36 | 37 | .. autofunction:: translate.write_stream 38 | 39 | 40 | Language Code Generation 41 | ---------------------------- 42 | 43 | .. autofunction:: translate.translation_table 44 | .. autofunction:: translate.print_table 45 | 46 | .. glossary:: 47 | 48 | translate 49 | Access to library is done primarily through the application called 50 | translate which will be installed and accessed through a directory 51 | under users $PATH envar. 52 | -------------------------------------------------------------------------------- /docs/img/command_line_tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjangsangy/py-translate/fe6279b2ee353f42ce73333ffae104e646311956/docs/img/command_line_tools.png -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. :index: 2 | 3 | =========================================== 4 | py-translate 5 | =========================================== 6 | **py-translate is a CLI Tool for Google Translate written in Python!** 7 | 8 | ------------------------------------------------------------------------ 9 | 10 | .. sidebar:: Current Supported Platforms 11 | 12 | Linux & Mac OS X 13 | 14 | :Author: Sang Han 2014 15 | :License: `Apache Software License v2 `_ 16 | :Version: v\ |version| 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | Quickstart Guide 21 | -------------------- 22 | .. toctree:: 23 | :maxdepth: 1 24 | 25 | README.rst 26 | 27 | Overview 28 | ---------------- 29 | .. toctree:: 30 | :maxdepth: 2 31 | :glob: 32 | 33 | users/* 34 | 35 | API Documentation 36 | ----------------- 37 | .. toctree:: 38 | :maxdepth: 2 39 | :glob: 40 | 41 | /devs/* 42 | 43 | Notes 44 | ------ 45 | .. toctree:: 46 | :maxdepth: 2 47 | 48 | HISTORY 49 | TODO 50 | 51 | Indices and tables 52 | ================== 53 | 54 | * :ref:`genindex` 55 | * :ref:`modindex` 56 | * :ref:`search` 57 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\py-translate.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\py-translate.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | -r ../requirements.txt 2 | 3 | sphinx_bootstrap_theme 4 | -------------------------------------------------------------------------------- /docs/users/examples.rst: -------------------------------------------------------------------------------- 1 | .. _examples: 2 | 3 | ================================================ 4 | Examples 5 | ================================================ 6 | 7 | Basic Usage 8 | ~~~~~~~~~~~~ 9 | .. code-block:: sh 10 | 11 | $ translate zh-TW <<< "Hello World!" 12 | 你好世界! 13 | 14 | $ translate ko <<< "Goodbye!" 15 | 안녕히 가세요! 16 | 17 | 18 | Redirect from File 19 | ~~~~~~~~~~~~~~~~~~ 20 | .. code-block:: sh 21 | 22 | $ translate zh-TW < "alice.txt" 23 | 24 | 阿麗思道:「你不是說你要告訴你的歷史嗎?告訴我你為甚麼恨—那個—那些—C和D,」 25 | 她末了兩個字母輕輕兒地說的,怕回來又得罪了牠。 26 | 27 | 那老鼠對著阿麗思嘆了一口氣道,「唉﹗我的身世說來可真是又長又苦又委屈呀—」 28 | 29 | 阿麗思聽了,瞧著那老鼠的尾巴說,「你這尾是曲啊﹗可是為甚麼又叫它苦呢﹗」 30 | 她就一頭聽著那老鼠說話,一頭在在心上納悶,所以她聽的那老鼠講的「尾曲」 31 | 的歷史是差不多像這個樣了的 32 | 33 | 34 | Unix Pipes! 35 | ~~~~~~~~~~~ 36 | .. code-block:: sh 37 | 38 | # Redirect any output through a unix pipe. 39 | $ python --help | translate fr 40 | 41 | .. code:: sh 42 | 43 | D'autres variables d'environnement 44 | 45 | PYTHONSTARTUP: le fichier exécuté au démarrage interactif (pas par défaut) 46 | PYTHONPATH: ':'-liste de répertoires séparés préfixés à la 47 |    module par défaut chemin de recherche. Le résultat est sys.path. 48 | PYTHONHOME: Annuaire suppléant (ou ). 49 | PYTHONCASEOK: ignorer la casse dans les états d'importation» (Windows). 50 | PYTHONIOENCODING: Codage [: erreurs] utilisés pour stdin / stdout / stderr. 51 | PYTHONHASHSEED: si cette variable est définie à aléatoire, l'effet est le même 52 |    comme spécifiant l'option-R: une valeur aléatoire est utilisée pour ensemencer les hashs de 53 |    str, octets et objets datetime. Il peut également être défini à un nombre entier 54 |    dans l'intervalle [0,4294967295] pour obtenir des valeurs de hachage avec une graine prévisible. 55 | 56 | :: 57 | 58 | Be Creative 59 | ~~~~~~~~~~~ 60 | .. code-block:: sh 61 | 62 | # A "Here-String" Grocery List 63 | $ cat <<- GROCERY_LIST | translate ko 64 | Celery 65 | Milk 66 | Eggs 67 | Bread 68 | Cereal 69 | GROCERY_LIST 70 | 71 | 셀러리 72 | 우유 73 | 달걀 74 | 빵 75 | 시리얼 76 | 77 | Chaining together Pipes 78 | ~~~~~~~~~~~~~~~~~~~~~~~ 79 | .. code-block:: sh 80 | 81 | # Translate Telephone! 82 | $ echo 'What is love?' | translate zh-TW | translate ko | translate fr | translate en 83 | What is love? 84 | 85 | 86 | 87 | Arguments 88 | ~~~~~~~~~ 89 | Requires at least one command line argument for the destination language. 90 | If no command line arguments are passed, an error message will be passed. 91 | 92 | .. code-block:: sh 93 | 94 | $ translate | "Error! No Arguments" 95 | 96 | .. describe:: 97 | usage: translate [-h] [-v] [-l [code]] [source] dest 98 | translate: error: the following arguments are required: dest 99 | 100 | See :ref:`usage` section for usage information 101 | 102 | Language Codes 103 | ~~~~~~~~~~~~~~ 104 | 105 | Use the -l option to see all the possible language codes. 106 | 107 | .. code-block:: sh 108 | 109 | $ translate -l 110 | 111 | Specify the output format by language code 112 | 113 | .. code-block:: sh 114 | 115 | $ translate -l zh-TW 116 | 117 | 118 | .. hlist:: 119 | :columns: 2 120 | 121 | .. cssclass:: table-hover 122 | .. csv-table:: 123 | :name: Language Codes 124 | :header: Language, Code 125 | 126 | Afrikaans,af 127 | Albanian,sq 128 | Arabic,ar 129 | Azerbaijani,az 130 | Basque,eu 131 | Belarusian,be 132 | Bengali,bn 133 | Bosnian,bs 134 | Bulgarian,bg 135 | Catalan,ca 136 | Cebuano,ceb 137 | Chinese (Simplified), zh 138 | Chinese (Traditional), zh-TW 139 | Croatian,hr 140 | Czech,cs 141 | Danish,da 142 | Dutch,nl 143 | English,en 144 | Esperanto,eo 145 | Estonian,et 146 | Filipino,tl 147 | Finnish,fi 148 | French,fr 149 | Galician,gl 150 | Georgian,ka 151 | German,de 152 | Greek,el 153 | Gujarati,gu 154 | Haitian,Creole ht 155 | Hebrew,iw 156 | Hindi,hi 157 | Hmong,hmn 158 | Hungarian,hu 159 | Icelandic,is 160 | Indonesian,id 161 | Irish,ga 162 | Italian,it 163 | Japanese,ja 164 | Javanese,jw 165 | Kannada,kn 166 | Khmer,km 167 | Korean,ko 168 | Lao,lo 169 | Latin,la 170 | Latvian,lv 171 | Lithuanian,lt 172 | Macedonian,mk 173 | Malay,ms 174 | Maltese,mt 175 | Marathi,mr 176 | Norwegian,no 177 | Persian,fa 178 | Polish,pl 179 | Portuguese,pt 180 | Romanian,ro 181 | Russian,ru 182 | Serbian,sr 183 | Slovak,sk 184 | Slovenian,sl 185 | Spanish,es 186 | Swahili,sw 187 | Swedish,sv 188 | Tamil,ta 189 | Telugu,te 190 | Thai,th 191 | Turkish,tr 192 | Ukrainian,uk 193 | Urdu,ur 194 | Vietnamese,vi 195 | Welsh,cy 196 | Yiddish,yi 197 | 198 | .. cssclass:: table-hover 199 | .. csv-table:: 200 | :name: Language Codes 201 | :header: Language, Code 202 | 203 | 土耳其文,tr 204 | 中文(繁體),zh-TW 205 | 中文(簡體),zh 206 | 丹麥文,da 207 | 巴斯克文,eu 208 | 日文,ja 209 | 爪哇語,jw 210 | 加里西亞文,gl 211 | 加泰羅尼亞文,ca 212 | 卡納達文,kn 213 | 布爾文,af 214 | 白俄羅斯語,be 215 | 立陶宛文,lt 216 | 冰島文,is 217 | 匈牙利文,hu 218 | 印尼文,id 219 | 印度文,hi 220 | 印度古哈拉地語,gu 221 | 西班牙文,es 222 | 克羅埃西亞文,hr 223 | 希伯來文,iw 224 | 希臘文,el 225 | 亞塞拜然文,az 226 | 孟加拉文,bn 227 | 拉丁文,la 228 | 拉脫維亞文,lv 229 | 法文,fr 230 | 波西尼亞,bs 231 | 波斯語,fa 232 | 波蘭文,pl 233 | 芬蘭文,fi 234 | 阿拉伯文,ar 235 | 阿爾巴尼亞文,sq 236 | 俄文,ru 237 | 保加利亞文,bg 238 | 威爾斯文,cy 239 | 苗文,hmn 240 | 英文,en 241 | 挪威文,no 242 | 泰文,th 243 | 泰米爾文,ta 244 | 泰盧固文,te 245 | 海地克里奧文,ht 246 | 烏克蘭文,uk 247 | 烏爾都語,ur 248 | 馬耳他文,mt 249 | 馬來文,ms 250 | 馬其頓文,mk 251 | 馬拉地文,mr 252 | 高棉文,km 253 | 國際語文,eo 254 | 宿霧文,ceb 255 | 捷克文,cs 256 | 荷蘭文,nl 257 | 喬治亞文,ka 258 | 斯瓦希里文,sw 259 | 斯洛伐克文,sk 260 | 斯洛維尼亞文,sl 261 | 菲律賓文,tl 262 | 越南文,vi 263 | 塞爾維亞文,sr 264 | 意第緒語,yi 265 | 愛沙尼亞文,et 266 | 愛爾蘭文,ga 267 | 瑞典文,sv 268 | 義大利文,it 269 | 葡萄牙文,pt 270 | 寮文,lo 271 | 德文,de 272 | 韓文,ko 273 | 羅馬尼亞文,ro 274 | -------------------------------------------------------------------------------- /docs/users/features.rst: -------------------------------------------------------------------------------- 1 | .. _features: 2 | 3 | ========= 4 | Features 5 | ========= 6 | 7 | - Simple command line parsing! 8 | - Written in pure Python! 9 | - Backwards compatable with Python 2.7 10 | - Supports all language from Google Translate API 11 | - The power of Unix pipes and filters 12 | - Native UTF-8 Support 13 | -------------------------------------------------------------------------------- /docs/users/install.rst: -------------------------------------------------------------------------------- 1 | .. _install: 2 | 3 | ============ 4 | Installation 5 | ============ 6 | 7 | From PyPI 8 | ~~~~~~~~~ 9 | * To install py-translate, simply: 10 | 11 | .. code-block:: bash 12 | 13 | $ pip install py-translate 14 | 15 | 16 | From Source 17 | ~~~~~~~~~~~ 18 | * Installation from the Git source repository. 19 | 20 | .. code-block:: bash 21 | 22 | $ git clone https://github.com/jjangsangy/py-translate.git 23 | 24 | * Use setup.py 25 | 26 | .. code-block:: bash 27 | 28 | $ python setup.py install 29 | 30 | OS X Installation 31 | ~~~~~~~~~~~~~~~~~ 32 | For full installation instructions for OS X, please visit :ref:`osx` 33 | -------------------------------------------------------------------------------- /docs/users/install_osx.rst: -------------------------------------------------------------------------------- 1 | .. _osx: 2 | 3 | Mac OS X Full Installation 4 | ========================== 5 | Mac OS X is a great development enviornment for python. However, using the 6 | default python installation which comes with the operating system 7 | currently (Mavericks 10.9.2), has many issues in terms of interfacing 8 | with third party applications. 9 | 10 | Before we can get hacking. We will need to do 3 things 11 | 12 | 1. **Get a C Compiler** 13 | 14 | * Install XCode 15 | * Install GCC using Apples Command Line Tools 16 | 17 | 2. **Get a Package Manager** 18 | 19 | * Install Homebrew 20 | 21 | 3. **Install Python** 22 | 23 | * Install your own copy of Python. No more messing with system copy. 24 | * Install pip 25 | 26 | 1. Installing XCode or Command Line Tools 27 | ------------------------------------------- 28 | By default, Apple does not package OS X with it's own C Compiler. 29 | 30 | The default way would be to download and install `XCode `_. 31 | which is free to anyone with an apple account and can be installed through the App Store. 32 | 33 | Another option for Lion, Mountain Lion and Mavericks users, 34 | **Apple now provides an official Command Line Tools for Xcode package** 35 | that you can install without needing to install Xcode itself! 36 | 37 | You can download it from `Apple's developer site `_ 38 | (free registration required) and search for "Command Line Tools". 39 | 40 | .. image:: ../img/command_line_tools.png 41 | :alt: command_line_tools 42 | 43 | 2. Install Homebrew 44 | ------------------- 45 | Once we have installed GCC and/or command line tools 46 | installing homebrew is very straightforward. 47 | 48 | Open up a terminal window and enter 49 | 50 | .. code-block:: bash 51 | 52 | $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" 53 | 54 | This will install the homebrew package manager in you ``/usr/local/``. 55 | 56 | Any packages that you will install, including python can be found 57 | in this directory. 58 | 59 | We also need to make sure that ``/usr/local/`` is in our ``$PATH`` 60 | enviornment before the ``/bin``. In order to do that, run this command. 61 | 62 | .. code-block:: bash 63 | 64 | echo export PATH="/usr/local/bin:$PATH" >> ~/.profile 65 | 66 | Now we're all set to start installing some packages! 67 | 68 | 3. Install Python 69 | ------------------ 70 | First make sure that homebrew is up to date 71 | 72 | .. code-block:: bash 73 | 74 | $ brew update && brew upgrade 75 | 76 | Already up-to-date. 77 | 78 | Now we are ready to install python. 79 | 80 | .. code-block:: bash 81 | 82 | $ brew install python 83 | 84 | .. note:: This will install python 2, not python 3. 85 | 86 | To install the latest version of Python 3. 87 | 88 | .. code-block:: bash 89 | 90 | $ brew install python3 91 | 92 | This will also include pip your python package manager. 93 | 94 | First we need to make sure that everything is up to date. 95 | 96 | .. code-block:: bash 97 | 98 | $ pip install --upgrade setuptools 99 | $ pip install --upgrade distribute 100 | $ pip install --upgrade pip 101 | $ pip install --upgrade wheel 102 | 103 | Now we're all ready, we can install py-translate directly from PyPI 104 | 105 | .. code-block:: bash 106 | 107 | $ pip install py-translate 108 | 109 | And we're done! 110 | -------------------------------------------------------------------------------- /docs/users/usage.rst: -------------------------------------------------------------------------------- 1 | .. _usage: 2 | 3 | ============== 4 | Usage 5 | ============== 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | :command:`translate [-h] [-V] [-l [code]] [source] dest` 10 | """""""""""""""""""""""""""""""""""""""""""""""""""""""" 11 | 12 | .. describe:: py-translate 13 | CLI Tool for Google Translate written in Python! 14 | 15 | ------------------------------------------------------------------------ 16 | 17 | positional arguments 18 | """""""""""""""""""" 19 | 20 | .. option:: source 21 | 22 | Source language code 23 | 24 | .. option:: dest 25 | 26 | Destination language code 27 | 28 | If only 1 positional argument is specified, it will be assumed 29 | to be dest and source will default to english 30 | 31 | ------------------------------------------------------------------------ 32 | 33 | optional arguments 34 | """"""""""""""""""" 35 | .. option:: -h, --help 36 | 37 | displays this help message and exit 38 | 39 | .. option:: -v, --version 40 | 41 | show program's version number and exit 42 | 43 | .. option:: -l, --lang [code] 44 | 45 | List out available language codes [can output in different languages] 46 | -------------------------------------------------------------------------------- /img/alice.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjangsangy/py-translate/fe6279b2ee353f42ce73333ffae104e646311956/img/alice.gif -------------------------------------------------------------------------------- /img/helloworld.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjangsangy/py-translate/fe6279b2ee353f42ce73333ffae104e646311956/img/helloworld.gif -------------------------------------------------------------------------------- /img/helloworld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jjangsangy/py-translate/fe6279b2ee353f42ce73333ffae104e646311956/img/helloworld.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | futures 2 | requests 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [nosetests] 2 | verbosity=2 3 | 4 | [metadata] 5 | description-file = README.rst 6 | 7 | [wheel] 8 | universal = 1 9 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | py-translate 4 | ============ 5 | A Translation Tool for Humans 6 | 7 | :copyright: (c) 2014 Sang Han 8 | """ 9 | 10 | from version import __version__, __release__, __build__ 11 | 12 | from setuptools import setup, find_packages 13 | from setuptools.command.test import test as TestCommand 14 | 15 | setup( 16 | name='py-translate', 17 | description='A Translation Tool for Humans', 18 | long_description='\n'.join( 19 | [ 20 | open('README.rst', 'rb').read().decode('utf-8'), 21 | open('HISTORY.rst', 'rb').read().decode('utf-8'), 22 | ] 23 | ), 24 | author='Sang Han', 25 | license='Apache License 2.0', 26 | url='https://github.com/jjangsangy/py-translate', 27 | author_email='jjangsangy@gmail.com', 28 | include_package_data=True, 29 | packages=find_packages(exclude=['*tests']), 30 | version=__version__, 31 | setup_requires=['futures', 'requests'], 32 | test_suite='translate.tests', 33 | cmdclass={'tests': TestCommand}, 34 | platforms='any', 35 | zip_safe=False, 36 | entry_points={ 37 | 'console_scripts': [ 38 | 'translate = translate.__main__:main' 39 | ] 40 | }, 41 | classifiers=[ 42 | 'Development Status :: 5 - Production/Stable', 43 | 'Environment :: Console', 44 | 'Intended Audience :: Developers', 45 | 'Natural Language :: English', 46 | 'License :: OSI Approved :: Apache Software License', 47 | 'Operating System :: OS Independent', 48 | 'Programming Language :: Unix Shell', 49 | 'Programming Language :: Python', 50 | 'Programming Language :: Python :: 2.7', 51 | 'Programming Language :: Python :: 3.3', 52 | 'Programming Language :: Python :: 3.4', 53 | 'Topic :: Software Development :: Libraries :: Python Modules', 54 | 'Topic :: Text Processing :: Linguistic', 55 | 'Topic :: Utilities', 56 | ], 57 | ) 58 | -------------------------------------------------------------------------------- /test_requirements.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | 3 | nose 4 | -------------------------------------------------------------------------------- /translate/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | py-translate 4 | ============ 5 | A Translation Tool for Humans 6 | ''' 7 | 8 | from .translator import * 9 | from .languages import * 10 | from .coroutines import * 11 | from .tests import TestTranslator, TestLanguages 12 | 13 | from .__version__ import __version__ 14 | from .__version__ import __build__ 15 | 16 | __title__ = 'py-translate' 17 | __author__ = 'Sang Han' 18 | __license__ = 'Apache Software License Version 2.0' 19 | __copyright__ = '(c) 2014 Sang Han' 20 | -------------------------------------------------------------------------------- /translate/__main__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Copyright: 2014 Sang Han 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | """ 17 | import sys 18 | 19 | from argparse import ArgumentParser, RawDescriptionHelpFormatter, FileType, REMAINDER 20 | from functools import partial 21 | 22 | 23 | from .__version__ import __version__, __build__ 24 | from .translator import translator 25 | from .coroutines import spool, source, set_task 26 | from .languages import print_table, translation_table 27 | 28 | __all__ = [] 29 | 30 | class TermWidthHelpFormatter(RawDescriptionHelpFormatter): 31 | 32 | def __init__(self, *args, **kwargs): 33 | super(TermWidthHelpFormatter, self).__init__( 34 | width=120, max_help_position=35, *args, **kwargs 35 | ) 36 | 37 | def command_line(): 38 | 39 | description = 'A Translation Tool for Humans' 40 | version = ' '.join([__version__, __build__]) 41 | table = sorted(translation_table('en').keys()) 42 | 43 | codes = ArgumentParser(add_help=False) 44 | codes.add_argument( 45 | '-l', '--list', 46 | nargs='?', 47 | default=False, 48 | const='en', 49 | metavar='code', 50 | dest='code', 51 | help=' '.join( 52 | [ 53 | 'Enumerate the name of country and language code pair.', 54 | 'Optionally specify output language', 55 | ]) 56 | ) 57 | 58 | # Preparse Language Code Flag 59 | language,_ = codes.parse_known_args() 60 | if language.code: 61 | print_table(language.code) 62 | exit(0) 63 | 64 | # Main Parser 65 | parser = ArgumentParser( 66 | parents=[codes], 67 | prog='translate', 68 | description=description, 69 | formatter_class=TermWidthHelpFormatter, 70 | ) 71 | parser.add_argument( 72 | '--translit', 73 | action='store_true', 74 | help='Print out the transliteration of the text', 75 | ) 76 | parser.add_argument( 77 | '-v', '--version', 78 | action='version', 79 | version="%s v%s" % ('translate', version) 80 | ) 81 | parser.add_argument( 82 | 'source', 83 | nargs='?', 84 | default=None, 85 | help='Source language code', 86 | metavar='source', 87 | ) 88 | parser.add_argument( 89 | 'dest', 90 | type=str, 91 | choices=table, 92 | help='Destination language code', 93 | metavar='target', 94 | ) 95 | parser.add_argument( 96 | 'text', 97 | nargs='?', 98 | default=sys.stdin, 99 | type=FileType('r'), 100 | help='Text file', 101 | metavar='file', 102 | ) 103 | 104 | return parser.parse_args() 105 | 106 | 107 | def main(): 108 | ''' 109 | Main Entry point for translator and argument parser 110 | ''' 111 | args = command_line() 112 | translate = partial(translator, args.source, args.dest, 113 | version=' '.join([__version__, __build__])) 114 | 115 | return source(spool(set_task(translate, translit=args.translit)), args.text) 116 | 117 | if __name__ == '__main__': 118 | sys.exit(main()) 119 | -------------------------------------------------------------------------------- /translate/__version__.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.0.3' 2 | __build__ = 'release' 3 | __release__ = __version__ + __build__ 4 | -------------------------------------------------------------------------------- /translate/coroutines.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | coroutines 4 | ~~~~~~~~~~ 5 | 6 | All functions definied within this file are essentially coroutines or 7 | helper functions for working with coroutines. 8 | 9 | Therefore members follow the coroutine pattern either as consumers, producers or 10 | consumer/producers 11 | """ 12 | 13 | from __future__ import print_function 14 | 15 | import sys 16 | import operator 17 | 18 | from functools import wraps, partial, reduce 19 | from concurrent.futures import ThreadPoolExecutor 20 | 21 | __all__ = ['coroutine', 'spool', 'source', 'set_task', 'write_stream', 'accumulator'] 22 | 23 | 24 | def coroutine(func): 25 | """ 26 | Initializes coroutine essentially priming it to the yield statement. 27 | Used as a decorator over functions that generate coroutines. 28 | 29 | .. code-block:: python 30 | 31 | # Basic coroutine producer/consumer pattern 32 | from translate import coroutine 33 | 34 | @coroutine 35 | def coroutine_foo(bar): 36 | try: 37 | while True: 38 | baz = (yield) 39 | bar.send(baz) 40 | 41 | except GeneratorExit: 42 | bar.close() 43 | 44 | :param func: Unprimed Generator 45 | :type func: Function 46 | 47 | :return: Initialized Coroutine 48 | :rtype: Function 49 | """ 50 | 51 | @wraps(func) 52 | def initialization(*args, **kwargs): 53 | 54 | start = func(*args, **kwargs) 55 | next(start) 56 | 57 | return start 58 | 59 | return initialization 60 | 61 | 62 | def accumulator(init, update): 63 | """ 64 | Generic accumulator function. 65 | 66 | .. code-block:: python 67 | 68 | # Simplest Form 69 | >>> a = 'this' + ' ' 70 | >>> b = 'that' 71 | >>> c = functools.reduce(accumulator, a, b) 72 | >>> c 73 | 'this that' 74 | 75 | # The type of the initial value determines output type. 76 | >>> a = 5 77 | >>> b = Hello 78 | >>> c = functools.reduce(accumulator, a, b) 79 | >>> c 80 | 10 81 | 82 | :param init: Initial Value 83 | :param update: Value to accumulate 84 | 85 | :return: Combined Values 86 | """ 87 | return ( 88 | init + len(update) 89 | if isinstance(init, int) else 90 | init + update 91 | ) 92 | 93 | 94 | def write_stream(script, output='trans'): 95 | """ 96 | :param script: Translated Text 97 | :type script: Iterable 98 | 99 | :param output: Output Type (either 'trans' or 'translit') 100 | :type output: String 101 | """ 102 | first = operator.itemgetter(0) 103 | sentence, _ = script 104 | printer = partial(print, file=sys.stdout, end='') 105 | 106 | for line in sentence: 107 | if isinstance(first(line), str): 108 | printer(first(line)) 109 | else: 110 | printer(first(line).encode('UTF-8')) 111 | 112 | printer('\n') 113 | 114 | return sys.stdout.flush() 115 | 116 | 117 | 118 | # TODO: Get rid of all this context crap 119 | @coroutine 120 | def set_task(translator, translit=False): 121 | """ 122 | Task Setter Coroutine 123 | 124 | End point destination coroutine of a purely consumer type. 125 | Delegates Text IO to the `write_stream` function. 126 | 127 | :param translation_function: Translator 128 | :type translation_function: Function 129 | 130 | :param translit: Transliteration Switch 131 | :type translit: Boolean 132 | """ 133 | # Initialize Task Queue 134 | task = str() 135 | queue = list() 136 | 137 | # Function Partial 138 | output = ('translit' if translit else 'trans') 139 | stream = partial(write_stream, output=output) 140 | workers = ThreadPoolExecutor(max_workers=8) 141 | 142 | try: 143 | while True: 144 | 145 | task = yield 146 | queue.append(task) 147 | 148 | except GeneratorExit: 149 | list(map(stream, workers.map(translator, queue))) 150 | 151 | @coroutine 152 | def spool(iterable, maxlen=1250): 153 | """ 154 | Consumes text streams and spools them together for more io 155 | efficient processes. 156 | 157 | :param iterable: Sends text stream for further processing 158 | :type iterable: Coroutine 159 | 160 | :param maxlen: Maximum query string size 161 | :type maxlen: Integer 162 | """ 163 | words = int() 164 | text = str() 165 | 166 | try: 167 | while True: 168 | 169 | while words < maxlen: 170 | stream = yield 171 | text = reduce(accumulator, stream, text) 172 | words = reduce(accumulator, stream, words) 173 | 174 | iterable.send(text) 175 | words = int() 176 | text = str() 177 | 178 | except GeneratorExit: 179 | iterable.send(text) 180 | iterable.close() 181 | 182 | 183 | def source(target, inputstream=sys.stdin): 184 | """ 185 | Coroutine starting point. Produces text stream and forwards to consumers 186 | 187 | :param target: Target coroutine consumer 188 | :type target: Coroutine 189 | 190 | :param inputstream: Input Source 191 | :type inputstream: BufferedTextIO Object 192 | """ 193 | for line in inputstream: 194 | 195 | while len(line) > 600: 196 | init, sep, line = line.partition(' ') 197 | assert len(init) <= 600 198 | target.send(''.join([init, sep])) 199 | 200 | target.send(line) 201 | 202 | inputstream.close() 203 | 204 | return target.close() 205 | -------------------------------------------------------------------------------- /translate/languages.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import print_function 3 | 4 | import json 5 | import operator 6 | 7 | from os.path import dirname, abspath, join, isfile 8 | 9 | __all__ = ['translation_table', 'print_table'] 10 | 11 | 12 | def translation_table(language, filepath='supported_translations.json'): 13 | ''' 14 | Opens up file located under the etc directory containing language 15 | codes and prints them out. 16 | 17 | :param file: Path to location of json file 18 | :type file: str 19 | 20 | :return: language codes 21 | :rtype: dict 22 | ''' 23 | fullpath = abspath(join(dirname(__file__), 'etc', filepath)) 24 | 25 | if not isfile(fullpath): 26 | raise IOError('File does not exist at {0}'.format(fullpath)) 27 | 28 | with open(fullpath, 'rt') as fp: 29 | raw_data = json.load(fp).get(language, None) 30 | assert(raw_data is not None) 31 | 32 | return dict((code['language'], code['name']) for code in raw_data) 33 | 34 | 35 | def print_table(language): 36 | ''' 37 | Generates a formatted table of language codes 38 | ''' 39 | table = translation_table(language) 40 | 41 | for code, name in sorted(table.items(), key=operator.itemgetter(0)): 42 | print(u'{language:<8} {name:\u3000<20}'.format( 43 | name=name, language=code 44 | )) 45 | 46 | return None 47 | -------------------------------------------------------------------------------- /translate/tests/__init__.py: -------------------------------------------------------------------------------- 1 | from .test_languages import TestLanguages 2 | from .test_translator import TestTranslator 3 | 4 | -------------------------------------------------------------------------------- /translate/tests/test_languages.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | try: 3 | import unittest2 as unittest 4 | except ImportError: 5 | import unittest 6 | 7 | import os 8 | import sys 9 | 10 | from ..languages import translation_table, print_table 11 | 12 | 13 | class TestLanguages(unittest.TestCase): 14 | 15 | 16 | def test_translation_table(self): 17 | table = translation_table('en') 18 | self.assertDictEqual( 19 | table, 20 | {'af': 'Afrikaans', 21 | 'ar': 'Arabic', 22 | 'az': 'Azerbaijani', 23 | 'be': 'Belarusian', 24 | 'bg': 'Bulgarian', 25 | 'bn': 'Bengali', 26 | 'bs': 'Bosnian', 27 | 'ca': 'Catalan', 28 | 'ceb': 'Cebuano', 29 | 'cs': 'Czech', 30 | 'cy': 'Welsh', 31 | 'da': 'Danish', 32 | 'de': 'German', 33 | 'el': 'Greek', 34 | 'en': 'English', 35 | 'eo': 'Esperanto', 36 | 'es': 'Spanish', 37 | 'et': 'Estonian', 38 | 'eu': 'Basque', 39 | 'fa': 'Persian', 40 | 'fi': 'Finnish', 41 | 'fr': 'French', 42 | 'ga': 'Irish', 43 | 'gl': 'Galician', 44 | 'gu': 'Gujarati', 45 | 'hi': 'Hindi', 46 | 'hmn': 'Hmong', 47 | 'hr': 'Croatian', 48 | 'ht': 'Haitian Creole', 49 | 'hu': 'Hungarian', 50 | 'id': 'Indonesian', 51 | 'is': 'Icelandic', 52 | 'it': 'Italian', 53 | 'iw': 'Hebrew', 54 | 'ja': 'Japanese', 55 | 'jw': 'Javanese', 56 | 'ka': 'Georgian', 57 | 'km': 'Khmer', 58 | 'kn': 'Kannada', 59 | 'ko': 'Korean', 60 | 'la': 'Latin', 61 | 'lo': 'Lao', 62 | 'lt': 'Lithuanian', 63 | 'lv': 'Latvian', 64 | 'mk': 'Macedonian', 65 | 'mr': 'Marathi', 66 | 'ms': 'Malay', 67 | 'mt': 'Maltese', 68 | 'nl': 'Dutch', 69 | 'no': 'Norwegian', 70 | 'pl': 'Polish', 71 | 'pt': 'Portuguese', 72 | 'ro': 'Romanian', 73 | 'ru': 'Russian', 74 | 'sk': 'Slovak', 75 | 'sl': 'Slovenian', 76 | 'sq': 'Albanian', 77 | 'sr': 'Serbian', 78 | 'sv': 'Swedish', 79 | 'sw': 'Swahili', 80 | 'ta': 'Tamil', 81 | 'te': 'Telugu', 82 | 'th': 'Thai', 83 | 'tl': 'Filipino', 84 | 'tr': 'Turkish', 85 | 'uk': 'Ukrainian', 86 | 'ur': 'Urdu', 87 | 'vi': 'Vietnamese', 88 | 'yi': 'Yiddish', 89 | 'zh': 'Chinese (Simplified)', 90 | 'zh-TW': 'Chinese (Traditional)'}) 91 | 92 | def test_codes(self): 93 | pass 94 | 95 | 96 | if __name__ == '__main__': 97 | unittest.main() 98 | -------------------------------------------------------------------------------- /translate/tests/test_translator.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | try: 3 | import unittest2 as unittest 4 | except ImportError: 5 | import unittest 6 | 7 | import os 8 | import sys 9 | 10 | from ..translator import translator 11 | 12 | class TestTranslator(unittest.TestCase): 13 | 14 | def test_love(self): 15 | love = translator('en', 'zh-TW', 'I love you')[0].pop() 16 | self.assertTrue(love) 17 | 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /translate/translator.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | translator 4 | ~~~~~~~~~~ 5 | 6 | Defines the interaction with the translation service. 7 | Since the program interfaces with the google web service, this 8 | module deals with the client side logic of pushing the translation request 9 | to the the server. 10 | """ 11 | 12 | import functools 13 | import requests 14 | import re 15 | import json 16 | 17 | from requests import Request, Session 18 | from requests.adapters import HTTPAdapter 19 | 20 | __all__ = ['push_url', 'translator'] 21 | 22 | def push_url(interface): 23 | ''' 24 | Decorates a function returning the url of translation API. 25 | Creates and maintains HTTP connection state 26 | 27 | Returns a dict response object from the server containing the translated 28 | text and metadata of the request body 29 | 30 | :param interface: Callable Request Interface 31 | :type interface: Function 32 | ''' 33 | 34 | @functools.wraps(interface) 35 | def connection(*args, **kwargs): 36 | """ 37 | Extends and wraps a HTTP interface. 38 | 39 | :return: Response Content 40 | :rtype: Dictionary 41 | """ 42 | session = Session() 43 | session.mount('http://', HTTPAdapter(max_retries=2)) 44 | session.mount('https://', HTTPAdapter(max_retries=2)) 45 | 46 | request = Request(**interface(*args, **kwargs)) 47 | prepare = session.prepare_request(request) 48 | response = session.send(prepare, verify=True) 49 | 50 | if response.status_code != requests.codes.ok: 51 | response.raise_for_status() 52 | 53 | cleanup = re.subn(r',(?=,)', '', response.content.decode('utf-8'))[0] 54 | 55 | return json.loads(cleanup.replace(r'\xA0', r' ').replace('[,', '[1,'), encoding='UTF-8') 56 | 57 | return connection 58 | 59 | @push_url 60 | def translator(source, target, phrase, version='0.0 test', charset='utf-8'): 61 | """ 62 | Returns the url encoded string that will be pushed to the translation 63 | server for parsing. 64 | 65 | List of acceptable language codes for source and target languages 66 | can be found as a JSON file in the etc directory. 67 | 68 | Some source languages are limited in scope of the possible target languages 69 | that are available. 70 | 71 | .. code-block:: python 72 | 73 | >>> from translate import translator 74 | >>> translator('en', 'zh-TW', 'Hello World!') 75 | '你好世界!' 76 | 77 | :param source: Language code for translation source 78 | :type source: String 79 | 80 | :param target: Language code that source will be translate into 81 | :type target: String 82 | 83 | :param phrase: Text body string that will be url encoded and translated 84 | :type phrase: String 85 | 86 | :return: Request Interface 87 | :rtype: Dictionary 88 | """ 89 | 90 | url = 'https://translate.google.com/translate_a/single' 91 | agent = 'User-Agent', 'py-translate v{}'.format(version) 92 | content = 'Content-Type', 'application/json; charset={}'.format(charset) 93 | 94 | params = {'client': 'a', 'ie': charset, 'oe': charset, 95 | 'dt': 't', 'sl': source, 'tl': target, 'q': phrase} 96 | 97 | request = {'method': 'GET', 98 | 'url': url, 99 | 'params': params, 100 | 'headers': dict([agent, content])} 101 | 102 | return request 103 | -------------------------------------------------------------------------------- /version.py: -------------------------------------------------------------------------------- 1 | exec(open('translate/__version__.py').read()) 2 | --------------------------------------------------------------------------------