"""Getting a message ready for translation (app/translation_prep.py)."""
from __future__ import annotations
from app.translation_prep import (
find_names,
find_names_in_signature,
join_wrapped_lines,
keep_symbols,
keep_terms,
split_pieces,
tidy,
translate_phrases,
)
KEPT = ''
def test_wrapped_lines_are_joined_but_paragraphs_kept() -> None:
assert join_wrapped_lines(" ask you about ask you about the schedule. Done. Hi Lukas, Best, {KEPT}Pozdrawiam,
the schedule.
then more
Natalia
Natalia
Natalia
Best results so far
", "en", "pl") assert translate_phrases("Best,
", "fr", "pl") == "Best,
" # no table def test_names_mid_sentence_but_not_headlines_or_german() -> None: html = "I came across Imaginary Pixels and Trusted Partner Network, in Spain.
" assert find_names(html, "en") == {"Imaginary Pixels", "Trusted Partner Network"} assert find_names("Why Matchmoving Matters, Editing Digger And More
", "en") == set() assert find_names("Wir haben das Neue Angebot gesehen.
", "de") == set() # Not across a sentence's end. assert find_names("working mostly in NukeX. My work includes paint.
", "en") == set() assert find_names_in_signature("Imaginary Pixels β visual effects studio") == [ "Imaginary Pixels" ] def test_kept_terms_and_spacing() -> None: out = keep_terms( "Hi Natalia Raz, see Imaginary Pixels.
", ["Natalia Raz", "Imaginary Pixels"] ) assert out == f"Hi {KEPT}Natalia Raz, see {KEPT}Imaginary Pixels.
" assert keep_terms("", ["Natalia"]) == "" assert tidy(f"nad {KEPT}Brutoni dalej") == f"nad {KEPT}Bruton i dalej" assert tidy("ab") == "ab" # the sender's own spans def test_emoji_kept() -> None: html = ( 'nice to e-meet you \nπ
' "Great ππ½ work β€οΈ
" ) out = keep_symbols(html) assert f"{KEPT}π" in out assert f"{KEPT}ππ½" in out assert f"{KEPT}β€οΈ" in out assert "nice to e-meet you" in out # the words still go to translation def test_file_names_kept() -> None: html = ( "See final_v2 and plate-03.exr, e.g. the U.S cut.
" ) out = keep_symbols(html) assert f"{KEPT}A_0023C017_260521_130157_p1CAC.mov" in out assert f"{KEPT}final_v2" in out assert f"{KEPT}plate-03.exr" in out assert "e.g. the U.S cut" in out # no file names there def test_symbols_not_marked_twice_or_in_attributes() -> None: html = ( f'{KEPT}https://x.io/a_b.mov' "" ) assert keep_symbols(html) == html def test_text_without_letters_is_kept() -> None: # A byte-order mark alone between tags came back as "Uzasadnienie". out = keep_symbols( 'β
{KEPT}β
" in out assert "WeChat: Jacquelineeeee_ WhatsApp: +48 780 549 877, for 1300 - 2500 Euro
" ) assert f"{KEPT}Jacquelineeeee_" in out assert f"{KEPT}+48 780 549 877" in out assert "1300 - 2500 Euro" in out # plain numbers stay in their sentence def test_paragraphs_split_at_block_tags() -> None: html = ( f"