Git Product home page Git Product logo

Comments (7)

ricki-z avatar ricki-z commented on June 26, 2024

This function sets session language to empty string if 'lang' argument is empty.

from devices.sensor.community.

ricki-z avatar ricki-z commented on June 26, 2024

But the language selection is added. Needs some css make over.

from devices.sensor.community.

Informatic avatar Informatic commented on June 26, 2024

Yeah, and session['lang'] == '' will effectively make line 19/20 fall back to automatic language selection. (('' or 'abc') == 'abc'; ('def' or 'abc') == 'def')

from devices.sensor.community.

ricki-z avatar ricki-z commented on June 26, 2024

I have checked this. 'lang' isn't set to automatic language. In the template layout.html there is an 'if' to set a class for active and inactive languages.
The following version sets all to inactive:

{% for language in AVAILABLE_LANGUAGES.items() %}
	{% if CURRENT_LANGUAGE == language[0] %}
		<li class="lang_active"><a name="language">{{ language[1] }}</a></li>
	{% else %}
		<li class="lang_inactive"><a href="?lang={{ language[0] }}">{{ language[1] }}</a></li>
	{%  endif %}
{% endfor %}

While this is working (BEST_MATCH_LANGUAGE is the best matching language):

{% for language in AVAILABLE_LANGUAGES.items() %}
	{% if CURRENT_LANGUAGE == language[0] or (CURRENT_LANGUAGE == '' and BEST_MATCH_LANGUAGE == language[0]) %}
		<li class="lang_active"><a name="language">{{ language[1] }}</a></li>
	{% else %}
		<li class="lang_inactive"><a href="?lang={{ language[0] }}">{{ language[1] }}</a></li>
	{%  endif %}
{% endfor %}

from devices.sensor.community.

ricki-z avatar ricki-z commented on June 26, 2024

For a test:
Set language by calling url with nonempty lang parameter. Then set the language with empty parameter. Call a different page by clicking one of the menu links.

from devices.sensor.community.

Informatic avatar Informatic commented on June 26, 2024

Code in webapp/common/context_processor.py was wrong all along (especially CURRENT_LANGUAGE you are using above).

This has been fixed in PR #11 by properly using flask_babel.get_locale when rendering the dropdown.

This is the behaviour with PR #11 applied, which I assume is valid:

$ http --session /tmp/test http://localhost:5000 | grep -i 'nav-link' | head -1 # defaults to english
                        <a href="/" class="nav-link">Home</a>
$ http --session /tmp/test http://localhost:5000/?lang=pl | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Strona główna</a>
$ http --session /tmp/test http://localhost:5000/ | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Strona główna</a>
$ http --session /tmp/test http://localhost:5000/?lang= | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Home</a>
$ http --session /tmp/test http://localhost:5000/ | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Home</a>
$ http --session /tmp/test http://localhost:5000/ Accept-Language:pl | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Strona główna</a>
$ http --session /tmp/test http://localhost:5000/ Accept-Language:en | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Home</a>
$ http --session /tmp/test http://localhost:5000/?lang=en Accept-Language:pl | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Home</a>
$ http --session /tmp/test http://localhost:5000/ Accept-Language:pl | grep -i 'nav-link' | head -1
                        <a href="/" class="nav-link">Home</a>

from devices.sensor.community.

ricki-z avatar ricki-z commented on June 26, 2024

Seems to work.

from devices.sensor.community.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.