"""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
the schedule.

") == ( "

ask you about the schedule.

" ) assert join_wrapped_lines("
ask you about
the schedule.
") == ( "
ask you about the schedule.
" ) text = '
ask you about\nthe schedule.\n\nThanks,\nAnna
' assert join_wrapped_lines(text) == ( '
ask you about the schedule.\n\nThanks,\nAnna
' ) # A new sentence, or a capital after the break: left alone. for html in ("

Done.
then more

", "

Hi Lukas,
Natalia

"): assert join_wrapped_lines(html) == html def test_sign_offs_come_from_the_phrase_table() -> None: assert translate_phrases("

Best,
Natalia

", "en", "pl") == ( f"

{KEPT}Pozdrawiam,
Natalia

" ) assert translate_phrases("
Mit freundlichen Grüßen
", "de", "en") == ( f"
{KEPT}Kind regards
" ) assert "Pozdrawiam" not in translate_phrases("

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}Bruton
i 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 = ( "
  • A_0023C017_260521_130157_p1CAC.mov
  • " "

    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( '
    \ufeff
    Dear Lukas,
     

    –

    ' ) assert f"{KEPT}\ufeff" in out assert "
     
    " in out # only spaces: nothing to keep assert f"

    {KEPT}–

    " in out assert "
    Dear Lukas,
    " in out def test_handles_and_phone_numbers_kept() -> None: out = keep_symbols( "

    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"
    Dear Anna,
    hello {KEPT}x.mov there
    " "

     

  • Item
  • " ) pieces, paragraphs = split_pieces(html) assert [p.text for p in paragraphs] == ["Dear Anna,", "hello x.mov there", "Item"] # The kept file name counts for the language but is not translated. assert [pieces[i] for i in paragraphs[1].pieces] == ["hello ", " there"]