コード例 #1
0
ファイル: __init__.py プロジェクト: pombredanne/kitdjango
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
コード例 #2
0
ファイル: models.py プロジェクト: pombredanne/kitdjango
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)
コード例 #3
0
ファイル: __init__.py プロジェクト: pombredanne/kitdjango
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
コード例 #4
0
ファイル: models.py プロジェクト: pombredanne/kitdjango
 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.")
コード例 #5
0
ファイル: models.py プロジェクト: ambv/kitdjango
 def lang(self):
     l = Language.from_id(self.language)
     return (l.name, l.desc)
コード例 #6
0
ファイル: models.py プロジェクト: pombredanne/kitdjango
 def lang(self):
     l = Language.from_id(self.language)
     return (l.name, l.desc)