Skip to content

Commit

Permalink
add language switcher drop-down to Marketplace (bug 740717)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Apr 11, 2012
1 parent e38475f commit 527c546
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions media/js/mkt/utils.js
Expand Up @@ -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();
});
13 changes: 13 additions & 0 deletions 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>
21 changes: 21 additions & 0 deletions mkt/site/tests/test_views.py
Expand Up @@ -4,6 +4,8 @@

import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
import waffle

import amo
import amo.tests
Expand Down Expand Up @@ -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')
1 change: 1 addition & 0 deletions mkt/templates/mkt/base.html
Expand Up @@ -69,6 +69,7 @@
{% else %}
<a class="button browserid" href="#">{{ _('Log in / Register') }}</a>
{% endif %}
{% include 'site/includes/languages.html' %}
</footer>
{% endblock %}

Expand Down

0 comments on commit 527c546

Please sign in to comment.