MCPcopy Index your code
hub / github.com/RustPython/RustPython / translation

Function translation

Lib/gettext.py:528–559  ·  view source on GitHub ↗
(domain, localedir=None, languages=None,
                class_=None, fallback=False)

Source from the content-addressed store, hash-verified

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