Return the most obvious language according the request.
357782
def get_language_from_request(request):
    """"""
    language = request.GET.get('language', None)
    if language:
        return language

    if hasattr(request, 'LANGUAGE_CODE'):
        lang = settings.PAGE_LANGUAGE_MAPPING(str(request.LANGUAGE_CODE))
        if lang not in LANGUAGE_KEYS:
            return settings.PAGE_DEFAULT_LANGUAGE
        else:
            return lang
    else:
        return settings.PAGE_DEFAULT_LANGUAGE
944105
def get_form(self, request, obj=None, **kwargs):
        
        form_class = super(TranslatableAdmin, self).get_form(request, obj, **kwargs)
        if self._has_translatable_model():
            form_class.language_code = self.get_form_language(request, obj)

        return form_class
1148765
protected function getBestLanguage(Request $request, $default = null)
    {
        foreach ($request->getLanguages() as $language) {
            if (strpos($language, '_') !== false) {
                return $language;
            }
        }

        return $default;
    }
922517
def queryset(self, request):
        
        qs = super(MultilingualInlineAdmin, self).queryset(request)
        # Don't now what the hell I was thinking here, but this code breaks stuff:
        #
        # checkfield = self.get_fill_check_field()
        # if checkfield is not None:
        #     kwargs = {str('%s_%s__isnull' % (checkfield, GLL.language_code)): False}
        #     from django.db.models.fields import CharField
        #     if isinstance(self.model._meta.translation_model._meta.get_field_by_name(checkfield)[0], CharField):
        #         kwargs[str('%s_%s__gt' % (checkfield, GLL.language_code))] = ''
        #     return qs.filter(**kwargs)
        return qs.filter(translations__language_code=GLL.language_code).distinct()
1130827
def get_queryset(self, request):
        
        qs = super(BaseTranslatableAdmin, self).get_queryset(request)

        if self._has_translatable_model():
            if not isinstance(qs, TranslatableQuerySet):
                raise ImproperlyConfigured("{0} class does not inherit from TranslatableQuerySet".format(qs.__class__.__name__))

            # Apply a consistent language to all objects.
            qs_language = self.get_queryset_language(request)
            if qs_language:
                qs = qs.language(qs_language)

        return qs
4129
def get_form_language(self, request, obj=None):
        
        if self._has_translatable_parent_model():
            return super(TranslatableInlineModelAdmin, self).get_form_language(request, obj=obj)
        else:
            # Follow the ?language parameter
            return self._language(request)
575633
def language(self):
        

        language_item = [subtag for subtag in self.subtags if subtag.type == 'language']

        return language_item[0] if len(language_item) > 0 else None
320181
def get_languages(self):
        """"""
        if self._languages_cache is None:
            self._languages_cache = list(self.iter_languages())
        return self._languages_cache
875524
def active_language(self):
        
        # Current instance language (if user uses activate_language() method)
        if self._language is not None:
            return self._language

        # Current site language (translation.get_language())
        current = utils.get_language()
        if current in self.supported_languages:
            return current

        # Default language descriptor
        return self.default_language
1166299
private function parseAcceptLanguage(Request $request)
    {
        $locales = [];
        $acceptLanguage = trim($request->headers->get('Accept-Language'));

        if (!empty($acceptLanguage)) {
            $locales = array_map(function (AcceptLanguage $acceptLanguage) {
                return $acceptLanguage->getType();
            }, $this->localeNegotiator->parse($acceptLanguage));
        }

        return $locales;
    }
160690
def for_language(self, language_code):
        
        clone = self._clone()
        clone._default_language = language_code
        return clone
632246
def json_requested():
    """"""
    best = request.accept_mimetypes.best_match(
        ['application/json', 'text/html'])
    return (best == 'application/json' and
            request.accept_mimetypes[best] >
            request.accept_mimetypes['text/html'])
1214886
def set_locale(request):
    """"""
    return request.query.get('lang', app.ps.babel.select_locale_by_request(request))
1010820
def language(self):
        """"""
        try:
            return self._language
        except AttributeError:
            self._language = find_language(self, getattr(self, 'exts', None))
        return self._language
68606
def get_main_language():
        
        try:
            main_language = TransLanguage.objects.filter(main_language=True).get()
            return main_language.code
        except TransLanguage.DoesNotExist:
            return TM_DEFAULT_LANGUAGE_CODE
1037546
def cell_language(source):
    """"""
    if source:
        line = source[0]
        if line.startswith('%%'):
            magic = line[2:]
            if ' ' in magic:
                lang, magic_args = magic.split(' ', 1)
            else:
                lang = magic
                magic_args = ''

            if lang in _JUPYTER_LANGUAGES:
                source.pop(0)
                return lang, magic_args

    return None, None
310487
private String determineLanguage(FacesContext fc, DataTable dataTable) {
		final List<String> availableLanguages = Arrays.asList("de", "en", "es", "fr", "hu", "it", "nl", "pl", "pt",
				"ru");
		if (BsfUtils.isStringValued(dataTable.getCustomLangUrl())) {
			return dataTable.getCustomLangUrl();
		} else if (BsfUtils.isStringValued(dataTable.getLang())) {
			String lang = dataTable.getLang();
			if (availableLanguages.contains(lang)) {
				return determineLanguageUrl(fc, lang);
			}
		} else {
			String lang = fc.getViewRoot().getLocale().getLanguage();
			if (availableLanguages.contains(lang)) {
				return determineLanguageUrl(fc, lang);
			}
		}
		return null;
	}