MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / translation

Function translation

tools/python-3.11.9-amd64/Lib/gettext.py:519–550  ·  view source on GitHub ↗
(domain, localedir=None, languages=None,
                class_=None, fallback=False)

Source from the content-addressed store, hash-verified

517
518
519def translation(domain, localedir=None, languages=None,
520 class_=None, fallback=False):
521 if class_ is None:
522 class_ = GNUTranslations
523 mofiles = find(domain, localedir, languages, all=True)
524 if not mofiles:
525 if fallback:
526 return NullTranslations()
527 from errno import ENOENT
528 raise FileNotFoundError(ENOENT,
529 'No translation file found for domain', domain)
530 # Avoid opening, reading, and parsing the .mo file after it's been done
531 # once.
532 result = None
533 for mofile in mofiles:
534 key = (class_, os.path.abspath(mofile))
535 t = _translations.get(key)
536 if t is None:
537 with open(mofile, 'rb') as fp:
538 t = _translations.setdefault(key, class_(fp))
539 # Copy the translation object to allow setting fallbacks and
540 # output charset. All other instance data is shared with the
541 # cached object.
542 # Delay copy import for speeding up gettext import when .mo files
543 # are not used.
544 import copy
545 t = copy.copy(t)
546 if result is None:
547 result = t
548 else:
549 result.add_fallback(t)
550 return result
551
552
553def install(domain, localedir=None, *, names=None):

Callers 5

installFunction · 0.85
dgettextFunction · 0.85
dngettextFunction · 0.85
dpgettextFunction · 0.85
dnpgettextFunction · 0.85

Calls 7

NullTranslationsClass · 0.85
add_fallbackMethod · 0.80
findFunction · 0.70
openFunction · 0.70
getMethod · 0.45
setdefaultMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected