Permalink
Browse files

add language switcher drop-down to Marketplace (bug 740717)

  • Loading branch information...
1 parent e38475f commit 527c5464c739f9ebd5323a79eeadf5b942dc771d @cvan cvan committed Apr 11, 2012
View
6 media/js/mkt/utils.js
@@ -53,3 +53,9 @@ $('html').ajaxSend(function(event, xhr, ajaxSettings) {
}).ajaxSuccess(function(event, xhr, ajaxSettings) {
$(window).trigger('resize'); // Redraw what needs to be redrawn.
});
+
+
+// If any field changes, submit the form.
+$('form.go').change(function() {
+ this.submit();
+});
View
13 mkt/site/templates/site/includes/languages.html
@@ -0,0 +1,13 @@
+<form class="go" id="lang-form" method="get">
+ <label for="language">{{ _('Other languages') }}:</label>
+ <select id="language" name="lang" dir="ltr">
+ {% for code, name in LANGUAGES|dictsort -%}
+ <option value="{{ code }}"{% if code == LANG|lower %} selected{% endif %}>
+ {{ name }}</option>
+ {%- endfor %}
+ </select>
+ {% for key, value in request.GET.items() %}
+ <input type="hidden" name="{{ key }}" value="{{ value }}">
+ {% endfor %}
+ <noscript><button type="submit">{{ _('Go') }}</button></noscript>
+</form>
View
21 mkt/site/tests/test_views.py
@@ -4,6 +4,8 @@
import mock
from nose.tools import eq_
+from pyquery import PyQuery as pq
+import waffle
import amo
import amo.tests
@@ -42,3 +44,22 @@ def test_engage_robots(self):
def test_do_not_engage_robots(self):
rs = self.client.get('/robots.txt')
self.assertContains(rs, 'Disallow: /')
+
+
+class TestFooter(amo.tests.TestCase):
+
+ def test_language_selector(self):
+ waffle.models.Switch.objects.create(name='unleash-consumer',
+ active=True)
+ r = self.client.get(reverse('home'))
+ eq_(r.status_code, 200)
+ eq_(pq(r.content)('#lang-form option[selected]').attr('value'),
+ 'en-us')
+
+ def test_language_selector_variables(self):
+ waffle.models.Switch.objects.create(name='unleash-consumer',
+ active=True)
+ r = self.client.get(reverse('home'), {'x': 'xxx', 'y': 'yyy'})
+ doc = pq(r.content)('#lang-form')
+ eq_(doc('input[type=hidden][name=x]').attr('value'), 'xxx')
+ eq_(doc('input[type=hidden][name=y]').attr('value'), 'yyy')
View
1 mkt/templates/mkt/base.html
@@ -69,6 +69,7 @@
{% else %}
<a class="button browserid" href="#">{{ _('Log in / Register') }}</a>
{% endif %}
+ {% include 'site/includes/languages.html' %}
</footer>
{% endblock %}

0 comments on commit 527c546

Please sign in to comment.