def install_templates_translations(generator):
 if ('JINJA_ENVIRONMENT' in generator.settings):
  jinja_extensions = generator.settings['JINJA_ENVIRONMENT'].get('extensions', [])
 else:
  jinja_extensions = generator.settings['JINJA_EXTENSIONS']
 if ('jinja2.ext.i18n' in jinja_extensions):
  domain = generator.settings.get('I18N_GETTEXT_DOMAIN', 'messages')
  localedir = generator.settings.get('I18N_GETTEXT_LOCALEDIR')
  if (localedir is None):
   localedir = os.path.join(generator.theme, 'translations')
  current_lang = generator.settings['DEFAULT_LANG']
  if (current_lang == generator.settings.get('I18N_TEMPLATES_LANG', _MAIN_LANG)):
   translations = gettext.NullTranslations()
  else:
   langs = [current_lang]
   try:
    translations = gettext.translation(domain, localedir, langs)
   except (IOError, OSError):
    _LOGGER.error("Cannot find translations for language '{}' in '{}' with domain '{}'. Installing NullTranslations.".format(langs[0], localedir, domain))
    translations = gettext.NullTranslations()
  newstyle = generator.settings.get('I18N_GETTEXT_NEWSTYLE', True)
  generator.env.install_gettext_translations(translations, newstyle)

def install_templates_translations ( generator ) : if ( 'JINJA_ENVIRONMENT' in generator . settings ) : jinja_extensions = generator . settings [ 'JINJA_ENVIRONMENT' ] . get ( 'extensions' , [ ] ) else : jinja_extensions = generator . settings [ 'JINJA_EXTENSIONS' ] if ( 'jinja2.ext.i18n' in jinja_extensions ) : domain = generator . settings . get ( 'I18N_GETTEXT_DOMAIN' , 'messages' ) localedir = generator . settings . get ( 'I18N_GETTEXT_LOCALEDIR' ) if ( localedir is None ) : localedir = os . path . join ( generator . theme , 'translations' ) current_lang = generator . settings [ 'DEFAULT_LANG' ] if ( current_lang == generator . settings . get ( 'I18N_TEMPLATES_LANG' , _MAIN_LANG ) ) : translations = gettext . NullTranslations ( ) else : langs = [ current_lang ] try : translations = gettext . translation ( domain , localedir , langs ) except ( IOError , OSError ) : _LOGGER . error ( "Cannot find translations for language '{}' in '{}' with domain '{}'. Installing NullTranslations." . format ( langs [ 0 ] , localedir , domain ) ) translations = gettext . NullTranslations ( ) newstyle = generator . settings . get ( 'I18N_GETTEXT_NEWSTYLE' , True ) generator . env . install_gettext_translations ( translations , newstyle )
install gettext translations in the jinja2 .