
module_cache = {}

def get_language(lang_code):
    """Return module with language localizations.

    This is a poor copy of the language framework of Docutils.
    """

    if lang_code in module_cache:
        return module_cache[lang_code]

    for i in (1, 0):
        try:
            module = __import__(lang_code, globals(), locals(), level=i)
            break
        except ImportError:
            continue
    else:
        module = __import__('en', globals(), locals(), level=1)

    module_cache[lang_code] = module
    return module


from importlib import import_module

module_cache = {}

def get_language(lang_code):
    """Return module with language localizations.

    This is a revamped version of function docutils.languages.get_language.
    """

    if lang_code in module_cache:
        return module_cache[lang_code]

    try:
        module = import_module('.' + lang_code, __name__)
    except ImportError:
        from . import en
        module = en

    module_cache[lang_code] = module
    return module

Use importlib.import_module instead of built-in __import__.
Use importlib.import_module instead of built-in __import__.

+ 
+ from importlib import import_module
  
  module_cache = {}
  
  def get_language(lang_code):
      """Return module with language localizations.
  
-     This is a poor copy of the language framework of Docutils.
+     This is a revamped version of function docutils.languages.get_language.
      """
  
      if lang_code in module_cache:
          return module_cache[lang_code]
  
-     for i in (1, 0):
-         try:
+     try:
+         module = import_module('.' + lang_code, __name__)
-             module = __import__(lang_code, globals(), locals(), level=i)
-             break
-         except ImportError:
+     except ImportError:
+         from . import en
+         module = en
-             continue
-     else:
-         module = __import__('en', globals(), locals(), level=1)
  
      module_cache[lang_code] = module
      return module
  
Use importlib.import_module instead of built-in __import__.
## Code Before:

module_cache = {}

def get_language(lang_code):
    """Return module with language localizations.

    This is a poor copy of the language framework of Docutils.
    """

    if lang_code in module_cache:
        return module_cache[lang_code]

    for i in (1, 0):
        try:
            module = __import__(lang_code, globals(), locals(), level=i)
            break
        except ImportError:
            continue
    else:
        module = __import__('en', globals(), locals(), level=1)

    module_cache[lang_code] = module
    return module

## Instruction:
Use importlib.import_module instead of built-in __import__.
## Code After:

from importlib import import_module

module_cache = {}

def get_language(lang_code):
    """Return module with language localizations.

    This is a revamped version of function docutils.languages.get_language.
    """

    if lang_code in module_cache:
        return module_cache[lang_code]

    try:
        module = import_module('.' + lang_code, __name__)
    except ImportError:
        from . import en
        module = en

    module_cache[lang_code] = module
    return module
