summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-01-11 06:37:07 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-01-11 06:37:07 (GMT)
commit2380a9e13fbcc0b79bdf66869c7589c740236539 (patch)
treece832daaafa9e4c21ccd1a6ff54c2461508916ce
parent2aa3dc739bef9ec180387f969fe2f82f428ae954 (diff)
downloadcpython-2380a9e13fbcc0b79bdf66869c7589c740236539.zip
cpython-2380a9e13fbcc0b79bdf66869c7589c740236539.tar.gz
cpython-2380a9e13fbcc0b79bdf66869c7589c740236539.tar.bz2
Add fallback argument to translation(). Set fallback to 1 for install().
Fixes #500595.
-rw-r--r--Lib/gettext.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index 638d4ae..6795ee6 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -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)