Пример #1
0
 def test_locale_remains_unchanged(self):
     """
     Always preserve the active locale.
     """
     lang = "pt-BR"
     with self.activate(lang):
         for locale in self.tested_locales:
             utils.get_best_locale(locale)
             eq_(get_language().lower(), lang.lower())
Пример #2
0
 def test_locale_remains_unchanged(self):
     """
     Always preserve the active locale.
     """
     lang = 'pt-BR'
     with self.activate(lang):
         for locale in self.tested_locales:
             utils.get_best_locale(locale)
             eq_(get_language().lower(), lang.lower())
Пример #3
0
 def test_first_supported_locale_for_language(self):
     """
     If neither the given locale or the locale resulting from activating the
     language code are supported, iterate through the supported locales and
     return the first one that matches the language.
     """
     eq_(utils.get_best_locale('es-AR').lower(), 'es-es')
Пример #4
0
 def test_first_supported_locale_for_language(self):
     """
     If neither the given locale or the locale resulting from activating the
     language code are supported, iterate through the supported locales and
     return the first one that matches the language.
     """
     eq_(utils.get_best_locale("es-AR").lower(), "es-es")
Пример #5
0
    def _decorated_view(request, *args, **kwargs):
        # Get locale from Facebook's `signed_request`
        signed_request = utils.unwrap_signed_request(request)
        try:
            facebook_locale = signed_request['user']['locale']
        except KeyError:
            pass
        else:
            # If user's locale isn't supported, get the next best one.
            # Defaults to en-US if no locale in same language as the
            # user's is found.
            best_locale = utils.get_best_locale(facebook_locale)

            prefix = urlresolvers.get_url_prefix()

            # Compare locales in lowercase just in case. Heh.
            # If we aren't using the best locale, redirect to it
            if prefix.locale.lower() != best_locale.lower():
                prefix.locale = best_locale
                locale_url = prefix.fix(request.path_info)
                query_string = urllib.urlencode(request.GET)
                final_url = ('?'.join([locale_url, query_string])
                             if query_string else locale_url)
                return redirect(final_url)

        return view_fn(request, *args, **kwargs)
Пример #6
0
    def test_always_returns_supported_locale(self):
        """
        Always return a supported locale.
        """
        supported_locales = [locale.lower()
            for locale in settings.FACEBOOK_LOCALES]

        for locale in self.tested_locales:
            best_locale = utils.get_best_locale(locale).lower()
            ok_(best_locale in supported_locales, 'The locale {best} (returned'
                ' for {locale}) is not a supported locale {supported}.'
                .format(locale=locale, best=best_locale,
                    supported=supported_locales))
Пример #7
0
    def test_always_returns_supported_locale(self):
        """
        Always return a supported locale.
        """
        supported_locales = [
            locale.lower() for locale in settings.FACEBOOK_LOCALES
        ]

        for locale in self.tested_locales:
            best_locale = utils.get_best_locale(locale).lower()
            ok_(
                best_locale in supported_locales, 'The locale {best} (returned'
                ' for {locale}) is not a supported locale {supported}.'.format(
                    locale=locale,
                    best=best_locale,
                    supported=supported_locales))
Пример #8
0
 def test_unsupported_locale(self):
     """
     Return the default en-US when locale isn't supported.
     """
     eq_(utils.get_best_locale('ar-LB').lower(), 'en-us')
Пример #9
0
 def test_locale_for_activated_language(self):
     """
     If the locale isn't supported, try to activate just the language code
     and return the resulting locale if supported.
     """
     eq_(utils.get_best_locale('en-ZA').lower(), 'en')
Пример #10
0
 def test_supported_locale(self):
     """
     Return the given locale if supported.
     """
     eq_(utils.get_best_locale('en-GB').lower(), 'en-gb')
Пример #11
0
 def test_unsupported_locale(self):
     """
     Return the default en-US when locale isn't supported.
     """
     eq_(utils.get_best_locale("ar-LB").lower(), "en-us")
Пример #12
0
 def test_locale_for_activated_language(self):
     """
     If the locale isn't supported, try to activate just the language code
     and return the resulting locale if supported.
     """
     eq_(utils.get_best_locale("en-ZA").lower(), "en")
Пример #13
0
 def test_supported_locale(self):
     """
     Return the given locale if supported.
     """
     eq_(utils.get_best_locale("en-GB").lower(), "en-gb")