Skip to content

Commit

Permalink
💻 Updated language dropdown (#5429)
Browse files Browse the repository at this point in the history
Fixes #5426 
Fixes #5459 

**How to test**

1. Log out and go to languages in the menu bar. Click the "help us translate" button
2. Search for a language with the English name
  • Loading branch information
Annelein authored May 6, 2024
1 parent df9b34a commit 5622ba5
Show file tree
Hide file tree
Showing 62 changed files with 245 additions and 13 deletions.
27 changes: 26 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Optional
from logging.config import dictConfig as logConfig
from os import path
from iso639 import languages

import static_babel_content
from markupsafe import Markup
Expand Down Expand Up @@ -2445,7 +2446,31 @@ def all_countries():
def other_languages(lang_param=None):
"""Return a list of language objects that are NOT the current language."""
current_lang = lang_param or g.lang
return [make_lang_obj(lang) for lang in ALL_LANGUAGES.keys() if lang != current_lang]
# these are the languages that iso doesn't have the English translations for
non_iso_transl = {
'kmr': 'Kurdish',
'nb_NO': 'Norwegian',
'pa_PK': 'Punjabi',
'pap': 'Papiamento',
'pt_BR': 'Portuguese',
'pt_PT': 'Portuguese',
'zh_Hans': 'Chinese',
'zh_Hant': 'Chinese'
}

# get all Hedy supported languages
other_langs = [make_lang_obj(lang) for lang in ALL_LANGUAGES.keys() if lang != current_lang]

# Get English names for all Hedy supported languages using iso639 and their codes
for lang_code in other_langs:
lang = lang_code.get('lang')
if lang in languages.part1:
language = languages.get(part1=lang)
lang_code['english'] = language.name
else:
lang_code['english'] = non_iso_transl.get(lang, '')

return other_langs


@app.template_global()
Expand Down
6 changes: 6 additions & 0 deletions build-tools/heroku/tailwind/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ code {
@apply text-green-600;
}

.add-language-item {
@apply text-gray-800 bg-green-400 no-underline hover:bg-green-500 hover:text-white py-2 px-4 block whitespace-nowrap;
@apply cursor-pointer w-52 font-medium rounded-md;
@apply grow-0;
}

.dropdown-item {
@apply text-gray-800 no-underline hover:bg-blue-600 py-2 px-4 block whitespace-nowrap;
@apply cursor-pointer w-52 font-medium rounded-md;
Expand Down
3 changes: 3 additions & 0 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ msgstr ""
msgid "add_students_options"
msgstr ""

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr ""

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ retrying==1.3.3
pytest==8.0.0
parameterized==0.8.1
Flask-Babel==4.0.0
iso-639>=0.4.5
iso3166~=2.0.2
turtlethread>=0.0.6
pre-commit==2.20.0
Expand Down
30 changes: 30 additions & 0 deletions static/css/generated.full.css
Original file line number Diff line number Diff line change
Expand Up @@ -344012,6 +344012,36 @@ code {
color: rgb(56 161 105 / var(--tw-text-opacity));
}

.add-language-item {
display: block;
white-space: nowrap;
--tw-bg-opacity: 1;
background-color: rgb(104 211 145 / var(--tw-bg-opacity));
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-left: 1rem;
padding-right: 1rem;
--tw-text-opacity: 1;
color: rgb(45 55 72 / var(--tw-text-opacity));
-webkit-text-decoration-line: none;
text-decoration-line: none;
}

.add-language-item:hover {
--tw-bg-opacity: 1;
background-color: rgb(72 187 120 / var(--tw-bg-opacity));
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}

.add-language-item {
width: 13rem;
cursor: pointer;
border-radius: 0.375rem;
font-weight: 500;
flex-grow: 0;
}

.dropdown-item {
display: block;
white-space: nowrap;
Expand Down
19 changes: 11 additions & 8 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,17 @@ export function initializeApp(options: InitializeAppOptions) {
});

$("#search_language").on('keyup', function() {
let search_query = ($("#search_language").val() as string).toLowerCase();
$(".language").each(function(){
if ($(this).html().toLowerCase().includes(search_query)) {
$(this).show();
} else {
$(this).hide();
}
});
let search_query = ($("#search_language").val() as string).toLowerCase();
$(".language").each(function(){
let languageName = $(this).html().toLowerCase();
let englishName = $(this).attr('data-english');
if (englishName !== undefined && (languageName.includes(search_query) || englishName.toLowerCase().includes(search_query))) {
$(this).show();
} else {
$(this).hide();
$("#add_language_btn").show();
}
});
});

// All input elements with data-autosubmit="true" automatically submit their enclosing form
Expand Down
5 changes: 4 additions & 1 deletion static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -99240,10 +99240,13 @@ def note_with_error(value, err):
$("#search_language").on("keyup", function() {
let search_query = $("#search_language").val().toLowerCase();
$(".language").each(function() {
if ($(this).html().toLowerCase().includes(search_query)) {
let languageName = $(this).html().toLowerCase();
let englishName = $(this).attr("data-english");
if (englishName !== void 0 && (languageName.includes(search_query) || englishName.toLowerCase().includes(search_query))) {
$(this).show();
} else {
$(this).hide();
$("#add_language_btn").show();
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion templates/incl/menubar.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@
</div>
<div class="flex flex-row flex-wrap w-min justify-start content-start items-start" style="max-height: {{((other_languages()|length)//3 + ((other_languages()|length)%3 > 0)*1)*3}}rem; width: 39rem;">
{% for lang in other_languages() %}
<div class="dropdown-item language" onclick="hedyApp.change_language ('{{lang.lang}}');event.preventDefault();" data-cy="switch-lang-{{lang.lang}}">{{ lang.sym }}</div>
<div class="dropdown-item language" data-english="{{ lang.english }}" onclick="hedyApp.change_language ('{{lang.lang}}');event.preventDefault();" data-cy="switch-lang-{{lang.lang}}">{{ lang.sym }}</div>
{% endfor %}

<a id="add_language_btn" class="add-language-item language" href="https://hosted.weblate.org/new-lang/hedy/adventures/">{{_('add_your_language')}}</a>
</div>
</div>
</li>
Expand Down
3 changes: 3 additions & 0 deletions translations/ar/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ msgstr "تلاميذ"
msgid "add_students_options"
msgstr "انشاء حسابات للتلاميذ"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/bg/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ msgstr "students"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/bn/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "students"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/ca/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ msgstr "Afegeix estudiants"
msgid "add_students_options"
msgstr "Afegeix opcions d'estudiants"

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr "Administrador"

Expand Down
3 changes: 3 additions & 0 deletions translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ msgstr "students"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/cy/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/da/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/de/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ msgstr "Schüler*innen hinzufügen"
msgid "add_students_options"
msgstr "Schüleroptionen hinzufügen"

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr "Administrator"

Expand Down
3 changes: 3 additions & 0 deletions translations/el/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ msgstr "μαθητών"
msgid "add_students_options"
msgstr "Δημιουργία λογαριασμών μαθητών"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr "Add your language!"

msgid "admin"
msgstr "Admin"

Expand Down
3 changes: 3 additions & 0 deletions translations/eo/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ msgstr "Aldoni lernantojn"
msgid "add_students_options"
msgstr "Krei kontojn de lernantoj"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/es/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ msgstr "Añadir estudiantes"
msgid "add_students_options"
msgstr "Añadir opciones de estudiantes"

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr "Admin"

Expand Down
3 changes: 3 additions & 0 deletions translations/et/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ msgstr "students"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/fa/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "students"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/fi/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/fr/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ msgstr "Ajouter des élèves"
msgid "add_students_options"
msgstr "Ajouter des options pour les élèves"

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr "Administration"

Expand Down
3 changes: 3 additions & 0 deletions translations/fy/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ msgstr "learlingen"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/he/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/hi/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ msgstr "छात्र"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/hu/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ msgstr "tanulók hozzáadása"
msgid "add_students_options"
msgstr "Create student accounts"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/ia/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/iba/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ msgstr "Add students"
msgid "add_students_options"
msgstr "Add students options"

msgid "add_your_language"
msgstr ""

#, fuzzy
msgid "admin"
msgstr "Admin"
Expand Down
3 changes: 3 additions & 0 deletions translations/id/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ msgstr "Tambahkan siswa-siswa"
msgid "add_students_options"
msgstr "Tambahkan opsi siswa"

msgid "add_your_language"
msgstr ""

msgid "admin"
msgstr "Admin"

Expand Down
Loading

0 comments on commit 5622ba5

Please sign in to comment.