2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
5 # Internationalization details are documented in
6 # <http://docutils.sf.net/docs/howto/i18n.html>.
9 This package contains modules for language-dependent features of Docutils.
12 __docformat__
= 'reStructuredText'
16 from docutils
.utils
import normalize_language_tag
17 if sys
.version_info
< (2,5):
18 from docutils
._compat
import __import__
22 def get_language(language_code
, reporter
=None):
23 """Return module with language localizations.
25 `language_code` is a "BCP 47" language tag.
26 If there is no matching module, warn and fall back to English.
28 # TODO: use a dummy module returning emtpy strings?, configurable?
29 for tag
in normalize_language_tag(language_code
):
30 tag
= tag
.replace('-','_') # '-' not valid in module names
32 return _languages
[tag
]
34 module
= __import__(tag
, globals(), locals(), level
=1)
37 module
= __import__(tag
, globals(), locals(), level
=0)
40 _languages
[tag
] = module
42 if reporter
is not None:
44 'language "%s" not supported: ' % language_code
+
45 'Docutils-generated text will be in English.')
46 module
= __import__('en', globals(), locals(), level
=1)
47 _languages
[tag
] = module
# warn only one time!