Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Language switcher #917

Merged
merged 5 commits into from
Jun 3, 2016
Merged

Language switcher #917

merged 5 commits into from
Jun 3, 2016

Conversation

zarino
Copy link
Member

@zarino zarino commented May 10, 2016

Language switcher for #676.

Closed:
closed

Open:
open

Feels a bit fiddly. Will revisit tomorrow morning with fresh eyes.

@@ -39,7 +39,7 @@ def create_simple_fields(apps, schema_editor):
),
SimpleField(
name='gender',
label=u"Gender (e.g. male”, “female)",
label=u"Gender (e.g. male, female)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! This change shouldn’t have been included in this PR. Can someone remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a fixup when we merge all this in to remove this.

@wfdd
Copy link
Contributor

wfdd commented May 16, 2016

A few observations:

  • get_language_info corrupts the language codes and names of languages not built into Django. It works fine with Argentinian Spanish:

    In [1]: from django.utils import translation
    
    In [2]: from django.conf import settings
    
    In [3]: settings.LANGUAGES
    Out[3]: 
    [('el', 'Greek'),
    ('en', 'English'),
    ('es-ar', 'Argentinian Spanish'),
    ('fr', 'French'),
    ('cy-gb', 'Welsh'),
    ('es-cr', 'Costa Rican Spanish')]
    
    In [4]: translation.get_language_info('es-ar')
    Out[4]: 
    {'bidi': False,
    'code': 'es-ar',
    'name': 'Argentinian Spanish',
    'name_local': 'español de Argentina'}

    But not the Costa Rican variety:

    In [5]: translation.get_language_info('es-cr')
    Out[5]: {'bidi': False, 'code': 'es', 'name': 'Spanish', 'name_local': 'español'}

    I think it'd be best to bypass get_language_info_list and list our languages for translation in mysite.extra_translations. We can extend django.conf.locale.LANG_INFO with Costa Rican Spanish and Welsh.

  • It should be possible to POST on click/select with XHR, serving the original dropdown to clients that support JavaScript. Having to press 'Go' is not ideal.

  • Perhaps in a separate PR, it should be made possible to override the User-Agent locale as the default locale.

@zarino
Copy link
Member Author

zarino commented May 17, 2016

It should be possible to POST on click/select with XHR, serving the original dropdown to clients that support JavaScript. Having to press 'Go' is not ideal.

Already working on it! 👍

@zarino
Copy link
Member Author

zarino commented May 17, 2016

@struan @mhl: Commit 31bb538 reverts all the custom dropdown menu styling and instead styles up the <select> element. If JavaScript is available, the submit button is hidden, and the form is automatically submitted whenever you change the <select> value.

language-switcher

Styling select boxes is the devil’s work, so I’ve tested this in IE8 and above, modern and old Firefox, and a few versions of Safari to check it all looks ok. In IE8–9 you get a duplication of dropdown arrows (one on the left, one on the right) but I think that's acceptable.

@mhl
Copy link
Contributor

mhl commented May 24, 2016

I think @wfdd's first point still needs to be addressed here - I'm assuming that's why the following fails:

  • (In chrome) set your first language to be Greek
  • Reload the front page, text appears in Greek as expected
  • Select Welsh from the language drop-down
  • The form is POSTed, the page reloads as expected, but the text is still in Greek <-- the bug
  • Select Argentinian Spanish from the language drop-down
  • The form is POSTed, the page reloads as expected, and the text is in Argentinian Spanish

}

LANG_INFO = dict(locale.LANG_INFO.items() + EXTRA_LANG_INFO.items())
locale.LANG_INFO = LANG_INFO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be neater to do locale.LANG_INFO.update(EXTRA_LANG_INFO) - I think the effect would be the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't concat dict.items in Python 3 anyway.

@struan struan changed the title WIP: Language switcher Language switcher Jun 1, 2016
zarino and others added 5 commits June 3, 2016 14:23
Uses a select and the built in django language selector. We add some JS
to autosubmit the form when you select an option from the dropdown. Need
to submit the form using POST as the built in selector only accepts post
requests.
set_language was broken in 1.8.10 so update to the latest 1.8 in order
to fix that.

See https://code.djangoproject.com/ticket/26308 for details
Foundation's suggested HTML for 4.3.2 includes loading a custom build of
Modernizr, but we weren't including that in Javascript.  This meant that
the class="no-js" on the <html> element was never changed to "js"; also
it's probable that some of the Foundation Javascript also relied on
Modernizr so it seems best to include it.

I would normally include a non-minified version of a third party
library, since django-pipeline will compress it for production anyway,
but I can't see an obvious way of getting this page:

   http://modernizr.com/download/#-inlinesvg-svg-svgclippaths-touch-shiv-mq-cssclasses-teststyles-prefixes-ie8compat-load

... to generate a non-minified version :(

Modernizr is MIT-licensed: https://modernizr.com/license/
If Django doesn't have the language info for a language then the
language switching code bails out on switching to the language. This
adds details for Welsh and Costa Rican Spanish to Django's language info
so these will work in the switcher.
Now we've added the language switcher there are two forms on the page
where the test expected one.
@struan struan merged commit f562976 into master Jun 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants