taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

repro_untranslated_contacts_mailbox.py (5722B)


      1 # This file is part of GNU Taler
      2 # (C) 2026 Taler Systems S.A.
      3 #
      4 # GNU Taler is free software; you can redistribute it and/or modify it under the
      5 # terms of the GNU General Public License as published by the Free Software
      6 # Foundation; either version 3, or (at your option) any later version.
      7 #
      8 # GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
      9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     10 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License along with
     13 # GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     14 """Reproducer: the contacts and mailbox screens stay English in every language.
     15 
     16 Their labels are string literals in the Compose sources rather than entries in
     17 strings.xml, so there is nothing for a translator to translate and nothing for
     18 ./check-translations.py to miss.
     19 
     20 The script's own navigation is the evidence.  Reaching Settings in a German
     21 wallet needs a bilingual pattern ("Settings|Einstellungen") because that label
     22 *is* translated; the two entries inside it, and every label on the screens they
     23 open, are matched in English alone -- and found.
     24 
     25 The app is restarted after the language is set, which is what a user does
     26 anyway, and which avoids the unrelated defect in
     27 `config-change-locks-the-wallet-out-of-its-database.md`.
     28 
     29     cd /opt/taler-sim/driver
     30     python3 ../findings/repro_untranslated_contacts_mailbox.py [emulator-5554]
     31 
     32 Exits 0 when English labels are on screen in a German wallet.  The per-app
     33 language needs no root (Android 13+) and is restored on the way out.
     34 """
     35 
     36 from __future__ import annotations
     37 
     38 import sys
     39 import time
     40 from pathlib import Path
     41 
     42 sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "driver"))
     43 
     44 from device import Device  # noqa: E402
     45 from wallet import Wallet  # noqa: E402
     46 
     47 # Labels with no entry in res/values/strings.xml, so no values-de/ can carry
     48 # them, per screen, with the (English) settings entry that opens it.
     49 SCREENS = {
     50     "Contacts": [r"^Add Contact$", r"^Petname$", r"^Alias$", r"^Alias Type$",
     51                  r"Lookup with Taldir", r"No contacts yet", r"Search contacts"],
     52     "Mailbox": [r"^Your Mailbox Address$", r"^Configure Mailbox URL$",
     53                 r"^Mailbox Base URL$", r"No messages yet", r"^Mailbox$"],
     54 }
     55 # These are translated, so the script has to know both spellings to get around.
     56 SETTINGS = r"(?i)^(Settings|Einstellungen)$"
     57 IN_SETTINGS = r"(?i)Developer mode|Entwicklermodus|Payment services|Bezahldienste"
     58 # A fresh wallet shows its welcome state rather than the four action
     59 # buttons, so the markers have to cover both.
     60 GERMAN_HOME = [r"^Einstellungen$", r"^QR-Code scannen$",
     61                r"Willkommen bei Taler Wallet", r"abheben",
     62                r"^Senden$", r"^Anfordern$"]
     63 
     64 
     65 HOME = r"(?i)^(Scan QR code|QR-Code scannen)$"
     66 
     67 
     68 def go_home(dev: Device) -> None:
     69     """Back out to the wallet's own home screen, in either language.
     70 
     71     Wallet.home() looks for the English "Scan QR code" only, so in a German
     72     wallet it presses back until the app itself is gone.
     73     """
     74     for _ in range(6):
     75         if dev.dump().find(HOME) is not None:
     76             return
     77         dev.back()
     78         time.sleep(1)
     79     # Backed out of the app altogether; bring it up again.
     80     dev.launch()
     81     time.sleep(8)
     82 
     83 
     84 def main() -> int:
     85     serial = sys.argv[1] if len(sys.argv) > 1 else "emulator-5554"
     86     dev = Device(serial)
     87     app = Wallet(dev)
     88 
     89     if dev.sdk_int < 33:
     90         print(f"this device is API {dev.sdk_int}; a per-app language needs 33+, "
     91               "so there is no way to switch the wallet's language from here")
     92         return 2
     93     try:
     94         dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False)
     95         app.fresh_start(dev_mode=True)
     96         app.home()
     97 
     98         dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales de-DE",
     99                   check=False)
    100         time.sleep(3)
    101         dev.stop()
    102         time.sleep(2)
    103         dev.launch()
    104         time.sleep(12)
    105         home = dev.dump()
    106         german = [p for p in GERMAN_HOME if home.find(f"(?i){p}") is not None]
    107         print(f"the wallet is in German: {[p.strip('^$') for p in german]}")
    108         print(f"  home screen: {' | '.join(home.texts()[:10])}")
    109         if not german:
    110             print("the language did not change; nothing to measure")
    111             return 1
    112 
    113         found: dict[str, list[str]] = {}
    114         for entry, labels in SCREENS.items():
    115             dev.tap_text(SETTINGS, timeout=30)
    116             dev.wait_for(IN_SETTINGS, timeout=30)
    117             app.scroll_to_text(rf"(?i)^{entry}$", max_scrolls=12)
    118             # The entry itself is matched in English, in a German wallet.
    119             dev.tap_text(rf"(?i)^{entry}$", timeout=20)
    120             time.sleep(3)
    121             shown = dev.dump()
    122             found[entry] = [l for l in labels
    123                             if shown.find(f"(?i){l}") is not None]
    124             print(f"\n=== {entry} (reached by its English name)")
    125             print("  " + " | ".join(shown.texts()[:14]))
    126             print(f"  {len(found[entry])} untranslatable labels: "
    127                   f"{[l.strip('^$') for l in found[entry]]}")
    128             go_home(dev)
    129 
    130         total = sum(len(v) for v in found.values())
    131         print(f"\nreproduced: {total >= 4} ({total} English labels in a German "
    132               f"wallet, plus the two settings entries that opened them)")
    133         return 0 if total >= 4 else 1
    134     finally:
    135         dev.shell(f"cmd locale set-app-locales {dev.pkg} --locales", check=False)
    136         print("restored the app's language")
    137 
    138 
    139 if __name__ == "__main__":
    140     sys.exit(main())