def get_langs(request, custom=None): """ get_langs(request) -> list of language IDs First there's the exact language as found in the request headers, followed by a generic form and by the ``LANGUAGE_CODE`` value from settings.""" langs = [] accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '*') if accept != '*': langs.append({'language': Language.id_from_name(request.LANGUAGE_CODE)}) langs.append({'language': Language.id_from_name(request.LANGUAGE_CODE.split("-")[0])}) if custom: langs.append(custom) langs.append({'language': Language.id_from_name(settings.LANGUAGE_CODE)}) langs.append({'language': Language.id_from_name(settings.LANGUAGE_CODE.split("-")[0])}) return langs
class Localized(db.Model): """Describes an abstract model which holds data in a specified ``language``. The language is chosen from the Language choices class but only from those specified in settings.LANGUAGES. The default value is settings.LANGUAGE_CODE.""" language = db.PositiveIntegerField( verbose_name=_("language"), choices=Language(filter=set([lang[0] for lang in settings.LANGUAGES])), default=Language.id_from_name(settings.LANGUAGE_CODE)) class Meta: abstract = True @property def lang(self): l = Language.from_id(self.language) return (l.name, l.desc)
def get_langs(request, custom=None): """ get_langs(request) -> list of language IDs First there's the exact language as found in the request headers, followed by a generic form and by the ``LANGUAGE_CODE`` value from settings.""" langs = [] accept = request.META.get('HTTP_ACCEPT_LANGUAGE', '*') if accept != '*': langs.append( {'language': Language.id_from_name(request.LANGUAGE_CODE)}) langs.append({ 'language': Language.id_from_name(request.LANGUAGE_CODE.split("-")[0]) }) if custom: langs.append(custom) langs.append({'language': Language.id_from_name(settings.LANGUAGE_CODE)}) langs.append({ 'language': Language.id_from_name(settings.LANGUAGE_CODE.split("-")[0]) }) return langs
def _get_default_tags_language(self): if hasattr(self, 'default_tags_language'): language_lookup_fields = [getattr(self, self.default_tags_language)] else: language_lookup_fields = ['language', 'lang'] for field_name in language_lookup_fields: try: _language = getattr(self, field_name) if isinstance(_language, tuple): _language = _language[0] if isinstance(_language, int): return _language elif isinstance(_language, basestring): return Language.id_from_name(_language) except AttributeError: continue raise ImproperlyConfigured("No compatible language field found for " "default tags.")
def lang(self): l = Language.from_id(self.language) return (l.name, l.desc)