Пример #1
0
    def to_native(self, obj):
        request = self.context['request']

        if request and request.method == 'GET' and 'lang' in request.GET:
            # We want to know if the user specifically requested a language,
            # in order to return only the relevant translations when that
            # happens.
            self.requested_language = find_language(request.GET['lang'].lower())

        app = self.create_fake_app(obj._source)
        return super(ESAppSerializer, self).to_native(app)
Пример #2
0
    def to_native(self, obj):
        request = self.context['request']

        if request and request.method == 'GET' and 'lang' in request.GET:
            # We want to know if the user specifically requested a language,
            # in order to return only the relevant translations when that
            # happens.
            self.requested_language = find_language(
                request.GET['lang'].lower())

        app = self.create_fake_app(obj._source)
        return super(ESAppSerializer, self).to_native(app)
Пример #3
0
def get_translations(src, attr, default_locale, lang):
    """
    Return dict of localized strings for attr or string if lang provided.

    If lang is provided, try to get the attr localized in lang, falling back to
    the app's default_locale and server language.

    If lang is not provided, we return all localized strings in the form::

        {"en": "English", "es": "Español"}

    """
    translations = src.get(attr, {})
    requested_language = find_language(lang)

    # If a language was requested, return only that translation.
    if requested_language:
        return (translations.get(requested_language) or
                translations.get(default_locale) or
                translations.get(settings.LANGUAGE_CODE) or u'')
    else:
        return translations or None
Пример #4
0
 def check(a, b):
     eq_(find_language(a), b)
Пример #5
0
 def check(a, b):
     eq_(find_language(a), b)