normalize_language_tag() now returns `BCP 47`_ conformant tags
[docutils.git] / docutils / parsers / rst / languages / __init__.py
blobc52989a4d01f79d8a80a635147242b096a631c7e
1 # $Id$
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>.
8 """
9 This package contains modules for language-dependent features of
10 reStructuredText.
11 """
13 __docformat__ = 'reStructuredText'
15 import sys
17 from docutils.utils import normalize_language_tag
18 if sys.version_info < (2,5):
19 from docutils._compat import __import__
21 _languages = {}
23 def get_language(language_code):
24 for tag in normalize_language_tag(language_code):
25 tag = tag.replace('-','_') # '-' not valid in module names
26 if tag in _languages:
27 return _languages[tag]
28 try:
29 module = __import__(tag, globals(), locals(), level=0)
30 except ImportError:
31 try:
32 module = __import__(tag, globals(), locals(), level=1)
33 except ImportError:
34 continue
35 _languages[tag] = module
36 return module
37 return None