-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from SUSYUSTC/dev
Dev
- Loading branch information
Showing
10 changed files
with
332 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ example_old | |
**egg** | ||
build | ||
**pycache** | ||
**TENCENT** | ||
**DEFAULT** | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rm -f ./main.aux ./main.log ./main.tex ./main.pdf | ||
rm -f ./main.aux ./main.log ./main.tex ./main.pdf ./text_new ./text_old |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
__version__ = "1.1.3" | ||
__version__ = "1.2.0" | ||
__author__ = "Jiace Sun" | ||
|
||
import os | ||
ROOT = os.path.dirname(os.path.abspath(__file__)) | ||
from . import config | ||
from .translate_tex import translate_tex | ||
from . import tencent | ||
from . import translation | ||
from .translation import translate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,47 @@ | ||
default_engine = 'google' | ||
default_language_from = 'en' | ||
default_language_to = 'zh-CN' | ||
import os | ||
from . import ROOT | ||
|
||
|
||
def read_variable(path, default): | ||
if os.path.exists(f'{ROOT}/{path}'): | ||
return open(f'{ROOT}/{path}').read().replace(' ', '').replace('\n', '') | ||
else: | ||
return default | ||
|
||
|
||
def set_variable(path, default): | ||
var = input().replace(' ', '').replace('\n', '') | ||
if var != '': | ||
return print(var, file=open(f'{ROOT}/{path}', 'w')) | ||
else: | ||
return default | ||
|
||
|
||
def reread(): | ||
global default_engine, default_language_from, default_language_to, tencent_secret_id, tencent_secret_key | ||
default_engine = read_variable(default_engine_path, default_engine_default) | ||
default_language_from = read_variable(default_language_from_path, default_language_from_default) | ||
default_language_to = read_variable(default_language_to_path, default_language_to_default) | ||
tencent_secret_id = read_variable(tencent_secret_id_path, tencent_secret_id_default) | ||
tencent_secret_key = read_variable(tencent_secret_key_path, tencent_secret_key_default) | ||
|
||
|
||
default_engine_path = 'DEFAULT_ENGINE' | ||
default_language_from_path = 'DEFAULT_LANGUAGE_FROM' | ||
default_language_to_path = 'DEFAULT_LANGUAGE_TO' | ||
tencent_secret_id_path = 'TENCENT_ID' | ||
tencent_secret_key_path = 'TENCENT_KEY' | ||
|
||
default_engine_default = 'google' | ||
default_language_from_default = 'en' | ||
default_language_to_default = 'zh-CN' | ||
tencent_secret_id_default = None | ||
tencent_secret_key_default = None | ||
|
||
default_engine = read_variable(default_engine_path, default_engine_default) | ||
default_language_from = read_variable(default_language_from_path, default_language_from_default) | ||
default_language_to = read_variable(default_language_to_path, default_language_to_default) | ||
tencent_secret_id = read_variable(tencent_secret_id_path, tencent_secret_id_default) | ||
tencent_secret_key = read_variable(tencent_secret_key_path, tencent_secret_key_default) | ||
|
||
math_code = 'XMATHX' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from tencentcloud.common import credential | ||
from tencentcloud.tmt.v20180321 import tmt_client | ||
from .config import tencent_secret_id, tencent_secret_key, math_code | ||
|
||
|
||
class Translator: | ||
def __init__(self): | ||
self.cred = credential.Credential(tencent_secret_id, tencent_secret_key) | ||
self.client = tmt_client.TmtClient(self.cred, 'ap-shanghai') | ||
|
||
def translate(self, text, language_to, language_from): | ||
request = tmt_client.models.TextTranslateRequest() | ||
request.Source = language_from | ||
request.Target = language_to | ||
request.SourceText = text | ||
request.ProjectId = 0 | ||
request.UntranslatedText = math_code | ||
result = self.client.TextTranslate(request) | ||
return result.TargetText |
Oops, something went wrong.