Permalink
Browse files

Move languages list from all pages, toggle if only two languages, or …

…link to full page instead
  • Loading branch information...
1 parent 1f2356e commit fea4508347dec02115d2947ac1d7d07e85fb9e62 @cnorthwood cnorthwood committed May 27, 2011
View
2 molly/apps/home/templates/home/index.html
@@ -103,7 +103,7 @@
<li class="round-bottom"><a href="{% url feedback:index %}?referer={% url home:index %}">Provide feedback</a></li>
</ul>
- {% include "language_selector.html" %}
+ {% include "i18n/language_selector.html" %}
{% block below-about %} {% endblock %}
View
11 molly/media/site/css/smart.css
@@ -849,7 +849,8 @@ small {
margin-right: 28px !important;
}
-.as-text-link
+.as-text-link,
+#bottom-links button
{
background: none !important;
border: 0 !important;
@@ -1039,4 +1040,12 @@ div#bottom-links div a {
-webkit-border-radius:0.4em;
-moz-border-radius:0.4em;
}
+
+#bottom-links button {
+ font-size: 9pt;
+ color: #00e !important;
+ text-decoration: underline;
+ font-weight: normal;
+ font-family: "Liberation Sans",sans-serif;
+}
/* End Bottom Links */
View
23 molly/templates/base.html
@@ -174,7 +174,26 @@ <h1 class="{% if not breadcrumbs.2 %}{{ breadcrumbs.0 }}-header with-icon{% endi
{% endif %}
{% if "feature_vote"|app_is_loaded or "feature-suggestions"|app_is_loaded %}
- <div class="full-width"><a href="{% url feature_vote:index %}">{% trans "Suggest a feature" %}</a></div>
+ <div><a href="{% url feature_vote:index %}">{% trans "Suggest a feature" %}</a></div>
+ {% endif %}
+ {# If there's only two languages to switch between, show the switch here #}
+ {% if LANGUAGES|length < 3 %}
+ <div>
+ {% for language_code, language_name in LANGUAGES %}
+ {% if language_code != LANGUAGE_CODE %}
+ <form action="{% url set-language %}" method="post" class="has-ajax-handler">
+ {% csrf_token %}
+ <a><button type="submit" name="language" value="{{ language_code }}">
+ {{ language_name }}
+ </button></a>
+ </form>
+ {% endif %}
+ {% endfor %}
+ </div>
+ {% else %}
+ {# Otherwise take to another page to choose language #}
+ {# This is always in English as it's a lingua franca #}
+ <div><a href="{% url set-language %}">Change language</a></div>
{% endif %}
<div style="clear:both"> </div>
{# Give a simple list for feature phones #}
@@ -188,8 +207,6 @@ <h1 class="{% if not breadcrumbs.2 %}{{ breadcrumbs.0 }}-header with-icon{% endi
{% endblock bottom_links %}
</div>
{% endif %}
-
- {% include "language_selector.html" %}
</div>
{% endblock body %}
View
5 molly/templates/i18n/index.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block content %}
+ {% include "i18n/language_selector.html" %}
+{% endblock %}
View
5 molly/urls.py
@@ -3,6 +3,7 @@
from django.contrib import admin
from molly.conf import applications, all_apps
+from molly.utils.i18n import SetLanguageView, javascript_catalog
# Admin
admin.autodiscover()
@@ -11,8 +12,8 @@
(r'^adm/', include(admin.site.urls)), # Admin site
(r'^comments/', include('django.contrib.comments.urls')), # Django comments
(r'', applications.home.urls), # Home default
- (r'set-language/$', 'django.views.i18n.set_language', {}, 'set-language'), # Change language view
- (r'^jsi18n/$', 'molly.utils.i18n.javascript_catalog',
+ (r'set-language/$', SetLanguageView, {}, 'set-language'), # Change language view
+ (r'^jsi18n/$', javascript_catalog,
{'packages': settings.INSTALLED_APPS}, 'js-i18n')) # JS i18n catalogues
# Dynamically add apps
View
16 molly/utils/i18n.py
@@ -2,6 +2,11 @@
from django.db.models import Model
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
+from django.views.i18n import set_language
+from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
+
+from molly.utils.views import BaseView
def name_in_language(obj, field):
try:
@@ -15,7 +20,16 @@ def name_in_language(obj, field):
else:
raise
-# TODO: When Molly moves to Django 1.3, this can be removed
+class SetLanguageView(BaseView):
+
+ def handle_GET(self, request, context):
+ return self.render(request, context, 'i18n/index')
+
+ def handle_POST(self, request, context):
+ # Do Django's built in language setter
+ return set_language(request)
+
+# TODO: When Molly moves to Django 1.4, this can be removed
"""
Below here contains backports from newer versions of Django, licensed under the

0 comments on commit fea4508

Please sign in to comment.