Beispiel #1
0
 def locale(self): 
     locale = request.params.get('locale')
     if locale is not None:
         try:
             set_session_locale(locale)
         except ValueError:
             abort(400, _('Invalid language specified'))
         try:
             set_lang(locale)
             # NOTE: When translating this string, substitute the word
             # 'English' for the language being translated into.
             # We do it this way because some Babel locales don't contain
             # a display_name!
             # e.g. babel.Locale.parse('no').get_display_name() returns None
             h.flash_notice(_("Language has been set to: English"))
         except:
             h.flash_notice(_("Language has been set to: English"))
     else:
         abort(400, _("No language given!"))
     return_to = get_redirect()
     if not return_to:
         # no need for error, just don't redirect
         return 
     return_to += '&' if '?' in return_to else '?'
     # hack to prevent next page being cached
     return_to += '__cache=%s' %  int(random.random()*100000000)
     redirect_to(return_to)
Beispiel #2
0
 def locale(self): 
     locale = request.params.get('locale')
     if locale is not None:
         try:
             set_session_locale(locale)
         except ValueError:
             abort(400, _('Invalid language specified'))
         try:
             set_lang(locale)
             # NOTE: When translating this string, substitute the word
             # 'English' for the language being translated into.
             # We do it this way because some Babel locales don't contain
             # a display_name!
             # e.g. babel.Locale.parse('no').get_display_name() returns None
             h.flash_notice(_("Language has been set to: English"))
         except:
             h.flash_notice(_("Language has been set to: English"))
     else:
         abort(400, _("No language given!"))
     return_to = get_redirect()
     if not return_to:
         # no need for error, just don't redirect
         return 
     return_to += '&' if '?' in return_to else '?'
     # hack to prevent next page being cached
     return_to += '__cache=%s' %  int(random.random()*100000000)
     redirect_to(return_to)
Beispiel #3
0
    def test_set_session_locale(self):
        set_session_locale('en')
        assert_equal(session['locale'], 'en')

        set_session_locale('fr')
        assert_equal(session['locale'], 'fr')
Beispiel #4
0
    def test_set_session_locale(self):
        set_session_locale('en')
        assert_equal(session['locale'], 'en')

        set_session_locale('fr')
        assert_equal(session['locale'], 'fr')