Spaces:
Sleeping
Sleeping
Download strings.py from danieldzikunuofmarvel/libog-twi: direct link, hf CLI and curl.
- Browser
- Download file 5.31 kB
-
https://huggingface.co/spaces/danieldzikunuofmarvel/libog-twi/resolve/main/strings.py
- Command line
-
hf download hf://spaces/danieldzikunuofmarvel/libog-twi/strings.py
-
curl -L -o strings.py https://huggingface.co/spaces/danieldzikunuofmarvel/libog-twi/resolve/main/strings.py
5.31 kB
| """Copy strings, verbatim from SPEC-03 §5 and §10.3. | |
| The spec says "Exact strings. Do not paraphrase." They live here alone, with no | |
| formatting applied, so `tests/test_app_strings.py` can assert them character for | |
| character against the spec tables. Change the spec first, then this file. | |
| COPY holds the strings that are the same in both languages. LANGUAGES holds the | |
| per-language overrides from §10.3. `t(key)` reads COPY; `t(key, lang)` prefers | |
| the override and falls back to COPY, so a key that never varies needs no entry. | |
| """ | |
| from __future__ import annotations | |
| COPY: dict[str, str] = { | |
| "title": "LIBOG Speech", | |
| "subtitle": ( | |
| "Speech recognition and speech synthesis for Asante Twi and Ewe, with English " | |
| "translation. Speak or type, and hear it back." | |
| ), | |
| "label.language": "Language", | |
| "banner.trained": "Trained on Bible readings.", | |
| "banner.detail": ( | |
| "Scripture vocabulary works best; everyday speech is coming in a later version." | |
| ), | |
| "label.listen": "Listen", | |
| "label.listen.dir": "your voice → Twi text", | |
| "label.speak": "Speak", | |
| "label.speak.dir": "Twi text → audio", | |
| "label.english": "English", | |
| "label.english.dir": "Twi text → English", | |
| "label.baseline": "For comparison, an off-the-shelf model:", | |
| "label.vowels": "Not on your keyboard:", | |
| "label.notfinetuned": "not fine-tuned", | |
| "btn.record": "Start recording", | |
| "btn.stop": "Stop recording", | |
| "btn.speak": "Speak this", | |
| "placeholder.twi": "Type Twi here, for example: Onyankopɔn dɔ wiase sɛɛ.", | |
| "placeholder.transcript": "Your words will appear here.", | |
| "err.no_sound": "I didn't hear anything. Check your microphone and try again.", | |
| "err.no_words": ( | |
| "I heard sound, but no words I could recognise. Try again, a little closer " | |
| "to the microphone." | |
| ), | |
| "err.no_text": "Type some Twi first, or use the vowel buttons above.", | |
| "warn.low_confidence": "That didn't sound like Twi, so this text is probably wrong.", | |
| "warn.truncated": ( | |
| "I used the first 30 seconds. Record shorter pieces for better results." | |
| ), | |
| "err.model_failed": "Something went wrong on our side. Try again in a moment.", | |
| "err.too_long": "That recording is too long. Please upload something under 10 minutes.", | |
| "footer.attrib": ( | |
| "Speech data from BibleTTS (CC BY-SA 4.0). Twi text restored from the Biblica " | |
| "Open Asante Twi Contemporary Bible (CC BY-SA 4.0), which supplies the special " | |
| "vowels missing from the released transcripts." | |
| ), | |
| "footer.privacy": "Your audio is processed and discarded. Nothing is stored.", | |
| "footer.disclaimer": ( | |
| "Speech recognition can be wrong. Do not rely on it for medical, legal, " | |
| "emergency or safety decisions." | |
| ), | |
| } | |
| # SPEC-03 §10.3. Only the keys that actually differ appear here; everything else | |
| # is shared and lives in COPY. `warn.low_confidence` deliberately has no Ewe | |
| # entry — §10.2 says the warning is not shown for Ewe at all, because the | |
| # threshold behind it was measured on Twi and does not transfer. | |
| LANGUAGES: dict[str, dict[str, str]] = { | |
| "twi": { | |
| "lang.name": "Asante Twi", | |
| "err.no_text": "Type some Twi first, or use the vowel buttons above.", | |
| "label.listen.dir": "your voice → Twi text", | |
| "label.speak.dir": "Twi text → audio", | |
| "label.english.dir": "Twi text → English", | |
| "placeholder.twi": "Type Twi here, for example: Onyankopɔn dɔ wiase sɛɛ.", | |
| "footer.attrib": ( | |
| "Speech data from BibleTTS (CC BY-SA 4.0). Twi text restored from the Biblica " | |
| "Open Asante Twi Contemporary Bible (CC BY-SA 4.0), which supplies the special " | |
| "vowels missing from the released transcripts." | |
| ), | |
| }, | |
| "ewe": { | |
| "lang.name": "Ewe", | |
| "err.no_text": "Type some Ewe first, or use the letter buttons above.", | |
| "label.listen.dir": "your voice → Ewe text", | |
| "label.speak.dir": "Ewe text → audio", | |
| "label.english.dir": "Ewe text → English", | |
| "placeholder.twi": "Type Ewe here, for example: Mawu lɔ̃ xexeame ale gbegbe.", | |
| "footer.attrib": ( | |
| "Speech data from BibleTTS (CC BY-SA 4.0). The Ewe transcripts are used as " | |
| "released — unlike the Asante Twi ones, they needed no repair." | |
| ), | |
| }, | |
| } | |
| DEFAULT_LANG = "twi" | |
| def t(key: str, lang: str | None = None) -> str: | |
| """Look up a copy string, failing loudly on a typo rather than rendering blank. | |
| With `lang`, the §10.3 override wins and COPY is the fallback — so a key that | |
| is the same in both languages needs no per-language entry. | |
| """ | |
| if lang is not None: | |
| if lang not in LANGUAGES: # pragma: no cover - developer error | |
| raise KeyError(f"No language named {lang!r}. See SPEC-03 §10.") | |
| override = LANGUAGES[lang].get(key) | |
| if override is not None: | |
| return override | |
| try: | |
| return COPY[key] | |
| except KeyError: # pragma: no cover - developer error, not a runtime path | |
| raise KeyError(f"No copy string named {key!r}. See SPEC-03 §5.") from None | |