Permalink
Browse files

Allow for languages to be changed from the UI (rather than use Accept…

…-Language headers)
  • Loading branch information...
1 parent 6b646f2 commit a05ee99964aec76891576d966662a1751445192d @cnorthwood cnorthwood committed May 26, 2011
@@ -103,7 +103,9 @@
<li class="round-bottom"><a href="{% url feedback:index %}?referer={% url home:index %}">Provide feedback</a></li>
</ul>
- {% block below-about %} {% endblock %}
+ {% include "language_selector.html" %}
+
+ {% block below-about %} {% endblock %}
{% if user.is_superuser %}
<hr/>
View
@@ -139,11 +139,11 @@ <h1 class="{% if not breadcrumbs.2 %}{{ breadcrumbs.0 }}-header with-icon{% endi
{% endcomment %}
{% if unread_user_messages %}
<div class="section" style="padding:10px;">
- <div class="bubble pad-10">
- <a href="{% url home:messages %}" style="font-size:1.2em; padding:1em 0.2em; display:block;">
- {% trans "You have a message from the developers!" %}
- </a>
- </div>
+ <div class="bubble pad-10">
+ <a href="{% url home:messages %}" style="font-size:1.2em; padding:1em 0.2em; display:block;">
+ {% trans "You have a message from the developers!" %}
+ </a>
+ </div>
</div>
{% endif %}
@@ -189,6 +189,8 @@ <h1 class="{% if not breadcrumbs.2 %}{{ breadcrumbs.0 }}-header with-icon{% endi
</div>
{% endif %}
+ {% include "language_selector.html" %}
+
</div>
{% endblock body %}
@@ -0,0 +1,27 @@
+{% load i18n %}
+{% get_current_language as LANGUAGE_CODE %}
+{% if LANGUAGES|length > 1 %}
+ <div class="section" style="clear:both;">
+ <div class="header">
+ <h2>{% trans "Change Language" %}</h2>
+ </div>
+ {% comment %}
+ It doesn't really have an AJAX handler, but we need to reload JS to get
+ the new JS language file, and we can't do this in the AJAX framework
+ {% endcomment %}
+ <form action="{% url set-language %}" method="post" class="has-ajax-handler">
+ {% csrf_token %}
+ <ul class="link-list">
+ {% for language_code, language_name in LANGUAGES %}
+ {% if language_code != LANGUAGE_CODE %}
+ <li><a>
+ <button class="as-text-link" type="submit" name="language" value="{{ language_code }}">
+ {{ language_name }}
+ </button>
+ </a></li>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ </form>
+ </div>
+{% endif %}
View
@@ -10,7 +10,8 @@
urlpatterns = patterns('',
(r'^adm/', include(admin.site.urls)), # Admin site
(r'^comments/', include('django.contrib.comments.urls')), # Django comments
- (r'', applications.home.urls)) # Home default
+ (r'', applications.home.urls), # Home default
+ (r'set-language', 'django.views.i18n.set_language', {}, 'set-language')) # Change language view
# Dynamically add apps
for app in (app for app in all_apps() if app.has_urlconf and app.local_name != 'home'):
@@ -2,12 +2,24 @@
from urllib import urlencode
from django.conf import settings
+from django.utils.translation import ugettext as _
+
+from molly.utils.i18n import override
def site_name(request):
return {
'site_name': settings.SITE_NAME if hasattr(settings, 'SITE_NAME') else 'Molly Project'
}
-
+
+def languages(request):
+ languages = []
+ for language_code, language_name in settings.LANGUAGES:
+ with override(language_code):
+ languages.append((language_code, _(language_name)))
+ return {
+ 'LANGUAGES': languages,
+ }
+
def full_path(request):
scheme, netloc, path, params, query, fragment = \
urlparse(request.get_full_path())

0 comments on commit a05ee99

Please sign in to comment.