Skip to content

Commit

Permalink
🚚 Rename Translation to Translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Oct 15, 2023
1 parent 3b51f31 commit 7fad1a2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions docs/resources/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ output style has been provided.
You can customize `config.process_output`:

```python
def process_output(translation):
def process_output(translations):
text = "\n".join(
"\n".join(
[rst["translator"] + ":", rst["paraphrase"] + rst["phonetic"]]
+ [k + " " + v for k, v in rst["explains"].items()]
)
for rst in translation.results
for rst in translations.results
)
return text

Expand Down
10 changes: 5 additions & 5 deletions src/translate_shell/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from argparse import Namespace
from typing import Any, Literal

from .translate import Translation
from .translate import Translations


class Configuration(Namespace):
Expand Down Expand Up @@ -64,16 +64,16 @@ def process_input(
)

@staticmethod
def process_output(translation: Translation) -> str:
def process_output(translations: Translations) -> str:
"""Process output.
:param translation:
:type translation: Translation
:param translations:
:type translations: Translations
:rtype: str
"""
from .utils.output import process_output

return process_output(translation)
return process_output(translations)

@staticmethod
def get_clipper() -> list[str]:
Expand Down
28 changes: 14 additions & 14 deletions src/translate_shell/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger(__name__)


class Translation(Namespace):
class Translations(Namespace):
"""Translation."""

def __init__(self, text: str, target_lang: str, source_lang: str) -> None:
Expand All @@ -39,27 +39,27 @@ def __init__(self, text: str, target_lang: str, source_lang: str) -> None:


def translate_once(
translator: Translator, translation: Translation, option: dict[str, Any]
translator: Translator, translations: Translations, option: dict[str, Any]
) -> None:
"""Translate once.
:param translator:
:type translator: Translator
:param translation:
:type translation: Translation
:param translations:
:type translations: Translations
:param option:
:type option: dict[str, Any]
:rtype: None
"""
res = translator(
translation.text,
translation.to_lang,
translation.from_lang,
translations.text,
translations.to_lang,
translations.from_lang,
option,
)
if res:
translation.results.append(deepcopy(res))
translation.status = 1
translations.results.append(deepcopy(res))
translations.status = 1


def translate(
Expand All @@ -68,7 +68,7 @@ def translate(
source_lang: str = "auto",
translators: list[Callable[[], Translator]] | list[str] | None = None,
options: dict[str, dict[str, Any]] | None = None,
) -> Translation:
) -> Translations:
"""Translate.
:param text:
Expand All @@ -87,7 +87,7 @@ def translate(
translators = ["google"]
if options is None:
options = {}
translation = Translation(text, target_lang, source_lang)
translations = Translations(text, target_lang, source_lang)

true_translators = []
for translator in translators:
Expand All @@ -100,7 +100,7 @@ def translate(
if len(translators) == 1:
translator = true_translators[0]
translate_once(
translator, translation, options.get(translator.name, {})
translator, translations, options.get(translator.name, {})
)
else:
threads = []
Expand All @@ -112,7 +112,7 @@ def translate(
target=translate_once,
args=(
translator,
translation,
translations,
options.get(translator.name, {}),
),
)
Expand All @@ -121,4 +121,4 @@ def translate(
list(map(lambda x: x.start(), threads))
list(map(lambda x: x.join(), threads))

return translation
return translations
8 changes: 4 additions & 4 deletions src/translate_shell/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,21 @@ def get_processed_result_text(
TRANSLATORS.get(translator, get_dummy(translator))
for translator in translator_names
]
translation = translate(
translations = translate(
text,
target_lang,
source_lang,
translators,
args.options,
)
if args.format == "json":
rst = json.dumps(vars(translation))
rst = json.dumps(vars(translations))
elif args.format == "yaml":
from ..external import yaml

rst = yaml.dump(vars(translation))
rst = yaml.dump(vars(translations))
else:
rst = args.process_output(translation)
rst = args.process_output(translations)
if rst and args.notification and is_sub_thread():
args.notify(rst)
return rst, text
Expand Down
18 changes: 9 additions & 9 deletions src/translate_shell/utils/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ..__main__ import ASSETS_PATH
from ..external.colorama import Fore, Style
from ..translate import Translation
from ..translate import Translations
from .misc import p10k_sections

NUMBER = json.loads(
Expand Down Expand Up @@ -79,15 +79,15 @@ def process_output_pos(pos: str) -> str:
return prompt


def process_output_p10k(translation: Translation) -> str:
def process_output_p10k(translations: Translations) -> str:
"""Process output p10k.
:param translation:
:type translation: Translation
:param translations:
:type translations: Translations
:rtype: str
"""
outputs = []
for rst in translation.results:
for rst in translations.results:
outputs += [process_output_firstline(rst)]
for i, explain in enumerate(rst["explains"].items(), 1):
outputs += [process_output_explain(explain)]
Expand All @@ -112,14 +112,14 @@ def process_output_p10k(translation: Translation) -> str:
return output


def process_output(translation: Translation) -> str:
def process_output(translations: Translations) -> str:
"""Process output.
:param translation:
:type translation: Translation
:param translations:
:type translations: Translations
:rtype: str
"""
rst = process_output_p10k(translation)
rst = process_output_p10k(translations)
with suppress(ImportError):
from repl_python_wakatime import wakatime_hook

Expand Down

0 comments on commit 7fad1a2

Please sign in to comment.