This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from parler.models import TranslatableModel, TranslatedFields | |
from django.utils.translation import ugettext as _ | |
# Create your models here. | |
class MyQuiz(TranslatableModel): | |
translations = TranslatedFields( | |
title=models.CharField( | |
_('Title'), max_length=250, default=True, unique=True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .models import MyQuiz | |
from parler.views import ViewUrlMixin | |
from django.views.generic import ListView | |
from django.template import add_to_builtins | |
class QuizListView(ViewUrlMixin, ListView): | |
model = MyQuiz | |
view_url_name = 'listing' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf.urls import patterns, include, url | |
from django.contrib import admin | |
from quiz2.views import QuizListView | |
admin.autodiscover() | |
urlpatterns = patterns('', | |
url(r'^$', QuizListView.as_view(), | |
name='listing'), | |
url(r'^admin/', include(admin.site.urls)), | |
url(r'^i18n/', include('django.conf.urls.i18n')), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LANGUAGE_CODE = 'fr-Fr' | |
PARLER_DEFAULT_LANGUAGE_CODE = 'fr' | |
PARLER_LANGUAGES = { | |
2: ( | |
{'code': 'en', }, | |
{'code': 'fr', }, | |
), | |
4: ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load i18n parler_tags %} | |
<ul> | |
{% for lang_code, title in LANGUAGES %} | |
{% get_language_info for lang_code as lang %} | |
{% get_translated_url lang_code as tr_url %} | |
{% if tr_url %}<li{% if lang_code == LANGUAGE_CODE %} class="is-selected"{% endif %}><a href="{{ tr_url }}" hreflang="{{ lang_code }}">{{ lang.name_local|capfirst }}</a></li>{% endif %} | |
{% endfor %} | |
</ul> |