Skip to content

Commit

Permalink
Fix errors with po dynamic merging
Browse files Browse the repository at this point in the history
  • Loading branch information
boryanagoncharenko committed Oct 7, 2024
1 parent d33b6fb commit f0d8264
Show file tree
Hide file tree
Showing 10 changed files with 697 additions and 694 deletions.
45 changes: 22 additions & 23 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
from safe_format import safe_format
from config import config

# gettext = gettext_with_fallback
from website.flask_helpers import render_template, proper_tojson, JinjaCompatibleJsonProvider, gettext_with_fallback
from website.flask_helpers import render_template, proper_tojson, JinjaCompatibleJsonProvider
from hedy_content import (ADVENTURE_ORDER_PER_LEVEL, KEYWORDS_ADVENTURES, ALL_KEYWORD_LANGUAGES,
ALL_LANGUAGES, COUNTRIES, HOUR_OF_CODE_ADVENTURES)

Expand Down Expand Up @@ -445,7 +444,9 @@ def before_request_https():

Compress(app)
Commonmark(app)
app.jinja_env.globals.update(_=gettext_with_fallback)

# Explicitly substitute the flask gettext function with our custom definition which uses fallback languages
app.jinja_env.globals.update(_=gettext)

trans_cache = {}

Expand All @@ -457,25 +458,23 @@ def before_request_https():
# with force_locale('en'):
# res = gettext(id)
# return res
# global trans_cache
#
# locale = session['lang']
#
# if locale not in trans_cache.keys():
# lang_trans = get_translations()
# if locale != 'en':
# try:
# with force_locale('en'):
# fallback_translation = get_translations()
# lang_trans.add_fallback(fallback_translation)
# finally:
# force_locale(locale)
# trans_cache[locale] = lang_trans
#
# t = trans_cache[locale].gettext(x)
# print(t)


# global trans_cache
#
# locale = session['lang']
#
# if locale not in trans_cache.keys():
# lang_trans = get_translations()
# if locale != 'en':
# try:
# with force_locale('en'):
# fallback_translation = get_translations()
# lang_trans.add_fallback(fallback_translation)
# finally:
# force_locale(locale)
# trans_cache[locale] = lang_trans
#
# t = trans_cache[locale].gettext(x)
# print(t)


# We don't need to log in offline mode
Expand Down Expand Up @@ -2346,7 +2345,7 @@ def favicon():
def main_page():
sections = hedyweb.PageTranslations('start').get_page_translations(g.lang)['home-sections']

my_test = gettext('no_programs')
# my_test = gettext('no_programs')

sections = sections[:]

Expand Down
17 changes: 4 additions & 13 deletions gettext_with_fallback.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
from flask import session
from flask_babel import gettext, force_locale


def gettext_with_fallback(x):
locale = session['lang']
res = gettext(x)
if locale != 'en' and res == x:
with force_locale('en'):
res = gettext(x)
return res
from flask_babel import gettext
from website.flask_helpers import gettext_with_fallback


# Explicitly substitute the flask_babel function gettext with our own implementation that
# adds a fallback language. Note that we need to monkey-patch instead of use the gettext_with_fallback
# directly because the extract function requires us to use gettext with literal strings.
gettext = gettext_with_fallback
# directly because the Babel extract function works if we use gettext with literal strings.
gettext = gettext_with_fallback # noqa
2 changes: 1 addition & 1 deletion highlighting/generate-rules-highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Import packages from the website app (AutoPep8 will mess this up, so disable it)
import sys
sys.path.append(path.abspath(path.join(path.dirname(__file__), '..'))) # noqa
from website.yaml_file import YamlFile
from website.yaml_file import YamlFile # noqa


# destinations of files containing syntax highlighting rules
Expand Down
58 changes: 29 additions & 29 deletions static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -61086,7 +61086,7 @@ ${o3}` : i3;
"successful_runs": "Successful runs: {successful_runs}",
"teacher_welcome": "Welcome to Hedy! Your are now the proud owner of a teachers account which allows you to create classes and invite students.",
"turtle": "\u{1F422}",
"unsaved_class_changes": "ANGL There are unsaved changes, are you sure you want to leave this page?"
"unsaved_class_changes": "There are unsaved changes, are you sure you want to leave this page?"
},
"eo": {
"CheckInternet": "Kontrolu, \u0109u via Interreta konekto funkcias \u011Duste.",
Expand Down Expand Up @@ -61142,28 +61142,28 @@ ${o3}` : i3;
"Transpile_success": "\xA1Buen trabajo!\n\xA1Increible!\n\xA1Bien hecho!\n\xA1Excelente!\n\xA1Lo hiciste genial!",
"Transpile_warning": "\xA1Cuidado!",
"Unsaved_Changes": "Tu programa no se ha guardado. \xBFDeseas irte sin guardarlo?",
"adventures_completed": "Adventures completed: {number_of_adventures}",
"adventures_completed": "Aventuras completadas: {number_of_adventures}",
"adventures_restored": "Se han restaurado las aventuras por defecto.",
"adventures_tried": "Adventures tried",
"adventures_tried": "Aventuras intentadas",
"copy_link_to_share": "Copiar enlace para compartir",
"customization_deleted": "Personalizaci\xF3n eliminada.",
"dice": "\u{1F3B2}",
"directly_available": "Directamente abierto",
"disabled": "Deshabilitado",
"errors": "Errors",
"errors": "Errores",
"fortune": "\u{1F52E}, \u2728",
"graph_title": "Errors per adventure completed on level {level}",
"graph_title": "Errores por aventura completada en el nivel {level}",
"haunted": "\u{1F987}, \u{1F47B}, \u{1F383}",
"level_title": "Nivel",
"multiple_keywords_warning": "Est\xE1 intentando utilizar la palabra clave {orig_keyword}, pero esta palabra clave puede tener varios significados. Por favor, elija la que est\xE1 intentando utilizar de esta lista y c\xF3piela y p\xE9guela en su c\xF3digo, llaves incluidas: {keyword_list}",
"number_of_errors": "Number of errors: {number_of_errors}",
"one_level_error": "You need to select at least one level.",
"number_of_errors": "N\xFAmero de errores: {number_of_errors}",
"one_level_error": "Debes seleccionar al menos un nivel.",
"restaurant": "\u{1F363}, \u{1F355}, \u{1F354}",
"rock": "\u2702\uFE0F, \u{1F4DC}, \u{1F5FB}",
"select_all": "Seleccionar todo",
"selected": "Seleccionado",
"songs": "\u{1F3B5},\u{1F3B6}",
"successful_runs": "Successful runs: {successful_runs}",
"successful_runs": "Ejecuciones exitosas: {successful_runs}",
"teacher_welcome": "\xA1Bienvenido/a a Hedy! Tu cuenta es de tipo profesor, por lo que puedes crear clases e invitar estudiantes.",
"turtle": "\u{1F422}",
"unsaved_class_changes": "Hay cambios sin guardar, \xBFest\xE1s seguro de que quieres abandonar esta p\xE1gina?"
Expand Down Expand Up @@ -62046,7 +62046,7 @@ ${o3}` : i3;
"successful_runs": "Successful runs: {successful_runs}",
"teacher_welcome": "Welcome to Hedy! Your are now the proud owner of a teachers account which allows you to create classes and invite students.",
"turtle": "\u{1F422}",
"unsaved_class_changes": "ANGL There are unsaved changes, are you sure you want to leave this page?"
"unsaved_class_changes": "There are unsaved changes, are you sure you want to leave this page?"
},
"om": {
"CheckInternet": "Check whether your Internet connection is working.",
Expand Down Expand Up @@ -62074,7 +62074,7 @@ ${o3}` : i3;
"fortune": "\u{1F52E}, \u2728",
"graph_title": "Errors per adventure completed on level {level}",
"haunted": "\u{1F987}, \u{1F47B}, \u{1F383}",
"level_title": "OM level title",
"level_title": "Level",
"multiple_keywords_warning": "You are trying to use the keyword {orig_keyword}, but this keyword might have several meanings. Please choose the one you're trying to use from this list and copy paste it in your code, curly braces included: {keyword_list}",
"number_of_errors": "Number of errors: {number_of_errors}",
"one_level_error": "You need to select at least one level.",
Expand All @@ -62086,7 +62086,7 @@ ${o3}` : i3;
"successful_runs": "Successful runs: {successful_runs}",
"teacher_welcome": "Welcome to Hedy! Your are now the proud owner of a teachers account which allows you to create classes and invite students.",
"turtle": "\u{1F422}",
"unsaved_class_changes": "ANGL There are unsaved changes, are you sure you want to leave this page?"
"unsaved_class_changes": "There are unsaved changes, are you sure you want to leave this page?"
},
"pa_PK": {
"CheckInternet": "Check whether your Internet connection is working.",
Expand Down Expand Up @@ -62502,31 +62502,31 @@ ${o3}` : i3;
"Transpile_success": "\u0414\u043E\u0431\u0430\u0440 \u043F\u043E\u0441\u0430\u043E!\n\u041D\u0435\u0432\u0435\u0440\u043E\u0432\u0430\u0442\u043D\u043E!\n\u0411\u0440\u0430\u0432\u043E!\n\u041E\u0434\u043B\u0438\u0447\u043D\u043E!\n\u0421\u0458\u0430\u0458\u043D\u043E \u0441\u0438 \u0443\u0440\u0430\u0434\u0438\u043E!",
"Transpile_warning": "\u0423\u043F\u043E\u0437\u043E\u0440\u0435\u045A\u0435!",
"Unsaved_Changes": "\u0418\u043C\u0430\u0442\u0435 \u043D\u0435\u0441\u0430\u0447\u0443\u0432\u0430\u043D \u043F\u0440\u043E\u0433\u0440\u0430\u043C. \u0414\u0430 \u043B\u0438 \u0436\u0435\u043B\u0438\u0442\u0435 \u0434\u0430 \u0438\u0437\u0430\u0452\u0435\u0442\u0435 \u0431\u0435\u0437 \u0447\u0443\u0432\u0430\u045A\u0430?",
"adventures_completed": "Adventures completed: {number_of_adventures}",
"adventures_restored": "Podrazumevane avanture su vra\u0107ene.",
"adventures_tried": "Adventures tried",
"copy_link_to_share": "Copy link to share",
"customization_deleted": "Customizations successfully deleted.",
"adventures_completed": "\u0417\u0430\u0432\u0440\u0448\u0435\u043D\u0435 \u0430\u0432\u0430\u043D\u0442\u0443\u0440\u0435: {number_of_adventures}",
"adventures_restored": "\u041F\u043E\u0434\u0440\u0430\u0437\u0443\u043C\u0435\u0432\u0430\u043D\u0435 \u0430\u0432\u0430\u043D\u0442\u0443\u0440\u0435 \u0441\u0443 \u0432\u0440\u0430\u045B\u0435\u043D\u0435.",
"adventures_tried": "\u041F\u043E\u043A\u0443\u0448\u0430\u043D\u0435 \u0430\u0432\u0430\u043D\u0442\u0443\u0440\u0435",
"copy_link_to_share": "\u041A\u043E\u043F\u0438\u0440\u0430\u0458 \u0432\u0435\u0437\u0443 \u0437\u0430 \u0434\u0435\u0459\u0435\u045A\u0435",
"customization_deleted": "\u041F\u0440\u0438\u043B\u0430\u0433\u043E\u0452\u0430\u0432\u0430\u045A\u0430 \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u043E\u0431\u0440\u0438\u0441\u0430\u043D\u0430.",
"dice": "\u{1F3B2}",
"directly_available": "Directly open",
"disabled": "Disabled",
"errors": "Errors",
"directly_available": "\u0414\u0438\u0440\u0435\u043A\u0442\u043D\u043E \u043E\u0442\u0432\u043E\u0440\u0438",
"disabled": "\u041E\u043D\u0435\u043C\u043E\u0433\u0443\u045B\u0435\u043D\u043E",
"errors": "\u0413\u0440\u0435\u0448\u043A\u0435",
"fortune": "\u{1F52E}, \u2728",
"graph_title": "Errors per adventure completed on level {level}",
"graph_title": "\u0413\u0440\u0435\u0448\u043A\u0435 \u043F\u043E \u0437\u0430\u0432\u0440\u0448\u0435\u043D\u043E\u0458 \u0430\u0432\u0430\u043D\u0442\u0443\u0440\u0438 \u043D\u0430 \u043D\u0438\u0432\u043E\u0443 {level}",
"haunted": "\u{1F987}, \u{1F47B}, \u{1F383}",
"level_title": "Nivo",
"multiple_keywords_warning": "You are trying to use the keyword {orig_keyword}, but this keyword might have several meanings. Please choose the one you're trying to use from this list and copy paste it in your code, curly braces included: {keyword_list}",
"number_of_errors": "Number of errors: {number_of_errors}",
"one_level_error": "You need to select at least one level.",
"level_title": "\u041D\u0438\u0432\u043E",
"multiple_keywords_warning": "\u041F\u043E\u043A\u0443\u0448\u0430\u0432\u0430\u0442\u0435 \u0434\u0430 \u043A\u043E\u0440\u0438\u0441\u0442\u0438\u0442\u0435 \u043A\u0459\u0443\u0447\u043D\u0443 \u0440\u0435\u0447 {orig_keyword}, \u0430\u043B\u0438 \u043E\u0432\u0430 \u043A\u0459\u0443\u0447\u043D\u0430 \u0440\u0435\u0447 \u043C\u043E\u0436\u0435 \u0438\u043C\u0430\u0442\u0438 \u043D\u0435\u043A\u043E\u043B\u0438\u043A\u043E \u0437\u043D\u0430\u0447\u0435\u045A\u0430. \u041C\u043E\u043B\u0438\u043C\u043E \u0432\u0430\u0441 \u0434\u0430 \u0438\u0437\u0430\u0431\u0435\u0440\u0435\u0442\u0435 \u043E\u043D\u0443 \u043A\u043E\u0458\u0443 \u043F\u043E\u043A\u0443\u0448\u0430\u0432\u0430\u0442\u0435 \u0434\u0430 \u043A\u043E\u0440\u0438\u0441\u0442\u0438\u0442\u0435 \u0441\u0430 \u043E\u0432\u0435 \u043B\u0438\u0441\u0442\u0435 \u0438 \u043A\u043E\u043F\u0438\u0440\u0430\u0442\u0435 \u0458\u0435 \u0443 \u0441\u0432\u043E\u0458 \u043A\u043E\u0434, \u0443\u043A\u0459\u0443\u0447\u0443\u0458\u0443\u045B\u0438 \u043A\u043E\u0432\u0440\u045F\u0430\u0432\u0435 \u0437\u0430\u0433\u0440\u0430\u0434\u0435: {keyword_list}",
"number_of_errors": "\u0411\u0440\u043E\u0458 \u0433\u0440\u0435\u0448\u0430\u043A\u0430: {number_of_errors}",
"one_level_error": "\u041C\u043E\u0440\u0430\u0442\u0435 \u0438\u0437\u0430\u0431\u0440\u0430\u0442\u0438 \u0431\u0430\u0440 \u0458\u0435\u0434\u0430\u043D \u043D\u0438\u0432\u043E.",
"restaurant": "\u{1F363}, \u{1F355}, \u{1F354}",
"rock": "\u2702\uFE0F, \u{1F4DC}, \u{1F5FB}",
"select_all": "Select all",
"selected": "Selected",
"select_all": "\u0418\u0437\u0430\u0431\u0435\u0440\u0438 \u0441\u0432\u0435",
"selected": "\u0418\u0437\u0430\u0431\u0440\u0430\u043D\u043E",
"songs": "\u{1F3B5},\u{1F3B6}",
"successful_runs": "Successful runs: {successful_runs}",
"teacher_welcome": "Welcome to Hedy! Your are now the proud owner of a teachers account which allows you to create classes and invite students.",
"successful_runs": "\u0423\u0441\u043F\u0435\u0448\u043D\u0430 \u0438\u0437\u0432\u0440\u0448\u0435\u045A\u0430: {successful_runs}",
"teacher_welcome": "\u0414\u043E\u0431\u0440\u043E\u0434\u043E\u0448\u043B\u0438 \u0443 Hedy! \u0421\u0430\u0434\u0430 \u0441\u0442\u0435 \u043F\u043E\u043D\u043E\u0441\u043D\u0438 \u0432\u043B\u0430\u0441\u043D\u0438\u043A \u043D\u0430\u043B\u043E\u0433\u0430 \u0437\u0430 \u043D\u0430\u0441\u0442\u0430\u0432\u043D\u0438\u043A\u0435 \u043A\u043E\u0458\u0438 \u0432\u0430\u043C \u043E\u043C\u043E\u0433\u0443\u045B\u0430\u0432\u0430 \u0434\u0430 \u043A\u0440\u0435\u0438\u0440\u0430\u0442\u0435 \u043E\u0434\u0435\u0459\u0435\u045A\u0430 \u0438 \u043F\u043E\u0437\u0438\u0432\u0430\u0442\u0435 \u0443\u0447\u0435\u043D\u0438\u043A\u0435.",
"turtle": "\u{1F422}",
"unsaved_class_changes": "There are unsaved changes, are you sure you want to leave this page?"
"unsaved_class_changes": "\u041F\u043E\u0441\u0442\u043E\u0458\u0435 \u043D\u0435\u0441\u0430\u0447\u0443\u0432\u0430\u043D\u0435 \u043F\u0440\u043E\u043C\u0435\u043D\u0435, \u0434\u0430 \u043B\u0438 \u0441\u0442\u0435 \u0441\u0438\u0433\u0443\u0440\u043D\u0438 \u0434\u0430 \u0436\u0435\u043B\u0438\u0442\u0435 \u0434\u0430 \u043D\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435 \u043E\u0432\u0443 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u0443?"
},
"sv": {
"CheckInternet": "Kontrollera att din internetanslutning fungerar.",
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit f0d8264

Please sign in to comment.