From cc38bce148cacbffdd9bc5bd18e3e1b1efb63ecd Mon Sep 17 00:00:00 2001 From: insolor Date: Fri, 22 Sep 2023 21:03:36 +0300 Subject: [PATCH] Drop outdated modules --- df_translation_toolkit/create_pot/batch.py | 33 -------------- .../create_pot/from_plain_text.py | 43 ------------------- 2 files changed, 76 deletions(-) delete mode 100644 df_translation_toolkit/create_pot/batch.py delete mode 100644 df_translation_toolkit/create_pot/from_plain_text.py diff --git a/df_translation_toolkit/create_pot/batch.py b/df_translation_toolkit/create_pot/batch.py deleted file mode 100644 index 368a055..0000000 --- a/df_translation_toolkit/create_pot/batch.py +++ /dev/null @@ -1,33 +0,0 @@ -from collections.abc import Callable -from pathlib import Path -from typing import NamedTuple - -import typer - -from df_translation_toolkit.create_pot.from_plain_text import main as create_pot_from_plain_text -from df_translation_toolkit.create_pot.from_raw_objects import main as create_pot_from_raw_objects -from df_translation_toolkit.create_pot.from_speech import main as create_pot_from_speech - - -class Parameters(NamedTuple): - function: Callable - pot_file_name: str - source_file_path: str - - -parameters = [ - Parameters(create_pot_from_raw_objects, "raws.pot", "raw/objects"), - Parameters(create_pot_from_speech, "speech.pot", "data/speech"), - Parameters(create_pot_from_plain_text, "text.pot", "raw/objects/text"), -] - - -def main(df_path: Path): - for function, pot_file_name, source_file_path in parameters: - with pot_file_name.open("w", encoding="utf-8") as pot_file: - print(f"Creating {pot_file_name} from {df_path / source_file_path}") - function(df_path / source_file_path, pot_file) - - -if __name__ == "__main__": - typer.run(main) diff --git a/df_translation_toolkit/create_pot/from_plain_text.py b/df_translation_toolkit/create_pot/from_plain_text.py deleted file mode 100644 index 4599fdc..0000000 --- a/df_translation_toolkit/create_pot/from_plain_text.py +++ /dev/null @@ -1,43 +0,0 @@ -import sys -from collections.abc import Iterable, Iterator, Sequence -from pathlib import Path - -import typer - -from df_translation_toolkit.parse.parse_plain_text import parse_plain_text_file -from df_translation_toolkit.utils.po_utils import TranslationItem, save_pot - - -def extract_translatables_from_file(file, file_path, join_paragraphs, keys): - for text_block, is_translatable, line_number in parse_plain_text_file(file, join_paragraphs): - if is_translatable: - if text_block in keys: - print("Key already exists:", repr(text_block), file=sys.stderr) - else: - keys.add(text_block) - yield TranslationItem(text=text_block.rstrip("\n"), source_file=file_path.name, line_number=line_number) - - -def extract_translatables(files: Iterable[Path], join_paragraphs: bool) -> Iterator[TranslationItem]: - keys = set() - for file_path in files: - if file_path.is_file(): - print(file_path, file=sys.stderr) - with file_path.open() as file: - yield from extract_translatables_from_file(file, file_path, join_paragraphs, keys) - - -def create_pot_file(pot_file: typer.FileBinaryWrite, files: Sequence[Path], join_paragraphs: bool): - save_pot( - pot_file, - extract_translatables(files, join_paragraphs), - ) - - -def main(path: Path, pot_file: typer.FileBinaryWrite, split: bool = True): - files = (file for file in path.rglob("*.txt") if file.is_file()) - create_pot_file(pot_file, sorted(files), not split) - - -if __name__ == "__main__": - typer.run(main)