comparison planemo/lib/python3.7/site-packages/docutils/languages/__init__.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 # $Id: __init__.py 8376 2019-08-27 19:49:29Z milde $
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
4
5 # Internationalization details are documented in
6 # <http://docutils.sf.net/docs/howto/i18n.html>.
7
8 """
9 This package contains modules for language-dependent features of Docutils.
10 """
11
12 __docformat__ = 'reStructuredText'
13
14 import sys
15
16 from docutils.utils import normalize_language_tag
17
18
19 _languages = {}
20
21 def get_language(language_code, reporter=None):
22 """Return module with language localizations.
23
24 `language_code` is a "BCP 47" language tag.
25 If there is no matching module, warn and fall back to English.
26 """
27 # TODO: use a dummy module returning emtpy strings?, configurable?
28 for tag in normalize_language_tag(language_code):
29 tag = tag.replace('-', '_') # '-' not valid in module names
30 if tag in _languages:
31 return _languages[tag]
32 try:
33 module = __import__(tag, globals(), locals(), level=1)
34 except ImportError:
35 try:
36 module = __import__(tag, globals(), locals(), level=0)
37 except ImportError:
38 continue
39 _languages[tag] = module
40 return module
41 if reporter is not None:
42 reporter.warning(
43 'language "%s" not supported: ' % language_code +
44 'Docutils-generated text will be in English.')
45 module = __import__('en', globals(), locals(), level=1)
46 _languages[tag] = module # warn only one time!
47 return module