mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Add fallback argument to translation(). Request fallbacks on install.
Fixes #500595.
This commit is contained in:
parent
57f61fb80b
commit
1be6419871
3 changed files with 12 additions and 4 deletions
|
@ -230,11 +230,14 @@ def find(domain, localedir=None, languages=None):
|
|||
# a mapping between absolute .mo file path and Translation object
|
||||
_translations = {}
|
||||
|
||||
def translation(domain, localedir=None, languages=None, class_=None):
|
||||
def translation(domain, localedir=None, languages=None,
|
||||
class_=None, fallback=0):
|
||||
if class_ is None:
|
||||
class_ = GNUTranslations
|
||||
mofile = find(domain, localedir, languages)
|
||||
if mofile is None:
|
||||
if fallback:
|
||||
return NullTranslations()
|
||||
raise IOError(ENOENT, 'No translation file found for domain', domain)
|
||||
key = os.path.abspath(mofile)
|
||||
# TBD: do we need to worry about the file pointer getting collected?
|
||||
|
@ -248,7 +251,7 @@ def translation(domain, localedir=None, languages=None, class_=None):
|
|||
|
||||
|
||||
def install(domain, localedir=None, unicode=0):
|
||||
translation(domain, localedir).install(unicode)
|
||||
translation(domain, localedir, fallback=1).install(unicode)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue