|
8 | 8 | such as converting Windows locale ID's to friendly names and presenting available languages. |
9 | 9 | """ |
10 | 10 |
|
11 | | -import builtins |
12 | 11 | import os |
13 | 12 | import sys |
14 | 13 | import ctypes |
|
27 | 26 | Optional, |
28 | 27 | Tuple, |
29 | 28 | Union, |
30 | | - Callable, |
31 | 29 | ) |
32 | 30 |
|
33 | 31 | #a few Windows locale constants |
@@ -290,52 +288,6 @@ def getAvailableLanguages(presentational: bool = False) -> List[Tuple[str, str]] |
290 | 288 | return langs |
291 | 289 |
|
292 | 290 |
|
293 | | -def makePgettext(translations): |
294 | | - """Obtain a pgettext function for use with a gettext translations instance. |
295 | | - pgettext is used to support message contexts, |
296 | | - but Python 3.7's gettext module doesn't support this, |
297 | | - so NVDA must provide its own implementation. |
298 | | - """ |
299 | | - if isinstance(translations, gettext.GNUTranslations): |
300 | | - def pgettext(context, message): |
301 | | - try: |
302 | | - # Look up the message with its context. |
303 | | - return translations._catalog[u"%s\x04%s" % (context, message)] |
304 | | - except KeyError: |
305 | | - return message |
306 | | - elif isinstance(translations, gettext.NullTranslations): |
307 | | - # A language without a translation catalog, such as English. |
308 | | - def pgettext(context, message): |
309 | | - return message |
310 | | - else: |
311 | | - raise ValueError("%s is Not a GNUTranslations or NullTranslations object" % translations) |
312 | | - return pgettext |
313 | | - |
314 | | - |
315 | | -def makeNpgettext( |
316 | | - translations: Union[None, gettext.GNUTranslations, gettext.NullTranslations], |
317 | | -) -> Callable[[str, str, str, Union[int, float]], str]: |
318 | | - """Obtain a npgettext function for use with a gettext translations instance. |
319 | | - npgettext is used to support message contexts with respect to ngettext, |
320 | | - but Python 3.7's gettext module doesn't support this, |
321 | | - so NVDA must provide its own implementation. |
322 | | - """ |
323 | | - if isinstance(translations, gettext.GNUTranslations): |
324 | | - def npgettext(context: str, msgSingular: str, msgPlural: str, n: Union[int, float]) -> str: |
325 | | - try: |
326 | | - # Look up the message with its context. |
327 | | - return translations._catalog[(f"{context}\x04{msgSingular}", translations.plural(n))] |
328 | | - except KeyError: |
329 | | - return msgSingular if n == 1 else msgPlural |
330 | | - elif isinstance(translations, gettext.NullTranslations): |
331 | | - # A language without a translation catalog, such as English. |
332 | | - def npgettext(context: str, msgSingular: str, msgPlural: str, n: Union[int, float]) -> str: |
333 | | - return msgSingular if n == 1 else msgPlural |
334 | | - else: |
335 | | - raise ValueError("%s is Not a GNUTranslations or NullTranslations object" % translations) |
336 | | - return npgettext |
337 | | - |
338 | | - |
339 | 291 | def getLanguageCliArgs() -> Tuple[str, ...]: |
340 | 292 | """Returns all command line arguments which were used to set current NVDA language |
341 | 293 | or an empty tuple if language has not been specified from the CLI.""" |
@@ -408,11 +360,8 @@ def setLanguage(lang: str) -> None: |
408 | 360 | if trans is None: |
409 | 361 | trans = _createGettextTranslation("en") |
410 | 362 |
|
411 | | - trans.install(names=['ngettext']) |
| 363 | + trans.install(names=["pgettext", "npgettext", "ngettext"]) |
412 | 364 | setLocale(getLanguage()) |
413 | | - # Install our pgettext and npgettext functions. |
414 | | - builtins.pgettext = makePgettext(trans) |
415 | | - builtins.npgettext = makeNpgettext(trans) |
416 | 365 |
|
417 | 366 | global installedTranslation |
418 | 367 | installedTranslation = weakref.ref(trans) |
|
0 commit comments