MCPcopy Index your code
hub / github.com/python/cpython / translation

Function translation

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

Source from the content-addressed store, hash-verified

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

Callers 5

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

Calls 8

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…