Commits

Zhang Huangbin committed cb2e612

Remove old translations.

  • Participants
  • Parent commits b481b04

Comments (0)

Files changed (3)

File controllers/ldap/basic.py

                 adminLib = admin.Admin()
                 lang = adminLib.getPreferredLanguage(userdn)
                 if lang is not False:
-                    web.render = iredutils.setRenderLang(web.render, lang)
+                    web.render = iredutils.setRenderLang(web.render, lang, oldlang=session.get('lang'),)
                     session['lang'] = lang
             except:
                 pass

File controllers/ldap/preferences.py

         cur_lang = self.langs.pop('cur_lang')
         if self.result is True:
             msg = 'SUCCESS'
-            web.render = iredutils.setRenderLang(web.render, cur_lang)
+            web.render = iredutils.setRenderLang(web.render, cur_lang, oldlang=session.get('lang'),)
         else:
             msg = self.result
 

File libs/iredutils.py

 
 cfg = web.iredconfig
 
-def setRenderLang(renderInst, lang):
+def get_translation(lang):
     # Init translations.
     if lang == 'en_US':
         translations = gettext.NullTranslations()
                     )
         except IOError:
             translations = gettext.NullTranslations()
+    return translations
 
-    renderInst._lookup.install_gettext_translations(translations)
+def setRenderLang(renderInst, lang, oldlang=None):
+    if oldlang is not None:
+        old_translation = get_translation(oldlang)
+        renderInst._lookup.uninstall_gettext_translations(old_translation)
+
+    new_translations = get_translation(lang)
+    renderInst._lookup.install_gettext_translations(new_translations)
     return renderInst
 
 def notfound():