Skip to content

Commit

Permalink
[CLEAN-UP] Removes 'u' parameter from all gettext() calls (hedyorg#2289)
Browse files Browse the repository at this point in the history
* Automatically replaced all gettext() calls

* Updated CONTRIBUTING.md

Co-authored-by: boryanagoncharenko <[email protected]>
  • Loading branch information
TiBiBa and boryanagoncharenko authored Mar 23, 2022
1 parent 53648b7 commit 00a9d29
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 281 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ Feel free to manually add the translation to as many languages as you know, but

When adding new Babel related translation the implementation is a bit more complex, but don't worry! It should al work fine with the following steps:
1. First we add the translation "placeholder" to either the front-end or back-end
* When on the front-end (in a .html template) we do this like this: {{ _('test') }}
* When on the back-end we do this like this: gettext(u'test')
* When on the front-end (in a .html template) we do this like this: ```{{ _('test') }}```
* Notice that the ```{{ }}``` characters are Jinja2 template placeholders for variables
* When on the back-end we do this like this: ```gettext('test')```
2. Next we run the following command to let Babel search for keys:
* ```pybabel extract -F babel.cfg -o messages.pot .```
3. We now have to add the found keys to all translation files, with the following command:
Expand Down
116 changes: 58 additions & 58 deletions app.py

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions coursedata/error-messages.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
gettext(u'Empty Program')
gettext(u'Wrong Level')
gettext(u'Incomplete')
gettext(u'Invalid')
gettext(u'Invalid Space')
gettext(u'Has Blanks')
gettext(u'No Indentation')
gettext(u'Unexpected Indentation')
gettext(u'Parse')
gettext(u'Unquoted Text')
gettext(u'Unquoted Assignment')
gettext(u'Unquoted Equality Check')
gettext(u'Var Undefined')
gettext(u'Cyclic Var Definition')
gettext(u'Lonely Echo')
gettext(u'Too Big')
gettext(u'Invalid Argument Type')
gettext(u'Invalid Argument')
gettext(u'Invalid Type Combination')
gettext(u'Unsupported Float')
gettext(u'Locked Language Feature')
gettext(u'Missing Command')
gettext(u'ask_needs_var')
gettext(u'echo_out')
gettext(u'space')
gettext(u'comma')
gettext(u'question mark')
gettext(u'newline')
gettext(u'period')
gettext(u'exclamation mark')
gettext(u'dash')
gettext(u'star')
gettext(u'single quotes')
gettext(u'double quotes')
gettext(u'slash')
gettext(u'string')
gettext(u'nested blocks')
gettext(u'or')
gettext(u'number')
gettext(u'integer')
gettext(u'float')
gettext(u'list')
gettext(u'input')
gettext('Empty Program')
gettext('Wrong Level')
gettext('Incomplete')
gettext('Invalid')
gettext('Invalid Space')
gettext('Has Blanks')
gettext('No Indentation')
gettext('Unexpected Indentation')
gettext('Parse')
gettext('Unquoted Text')
gettext('Unquoted Assignment')
gettext('Unquoted Equality Check')
gettext('Var Undefined')
gettext('Cyclic Var Definition')
gettext('Lonely Echo')
gettext('Too Big')
gettext('Invalid Argument Type')
gettext('Invalid Argument')
gettext('Invalid Type Combination')
gettext('Unsupported Float')
gettext('Locked Language Feature')
gettext('Missing Command')
gettext('ask_needs_var')
gettext('echo_out')
gettext('space')
gettext('comma')
gettext('question mark')
gettext('newline')
gettext('period')
gettext('exclamation mark')
gettext('dash')
gettext('star')
gettext('single quotes')
gettext('double quotes')
gettext('slash')
gettext('string')
gettext('nested blocks')
gettext('or')
gettext('number')
gettext('integer')
gettext('float')
gettext('list')
gettext('input')
2 changes: 1 addition & 1 deletion hedyweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def render_code_editor_with_tabs(level_defaults, max_level, level_number, versio
user = current_user()

if not level_defaults:
return utils.error_page(error=404, ui_message=gettext(u'no_such_level'))
return utils.error_page(error=404, ui_message=gettext('no_such_level'))


arguments_dict = {}
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ def markdown_to_html_tags(markdown):
def error_page(error=404, page_error=None, ui_message=None, menu=True, iframe=None):
if error not in [403, 404, 500]:
error = 404
default = gettext(u'default_404')
default = gettext('default_404')
if error == 403:
default = gettext(u'default_403')
default = gettext('default_403')
elif error == 500:
default = gettext(u'default_500')
default = gettext('default_500')
return render_template("error-page.html", menu=menu, error=error, iframe=iframe,
page_error=page_error or ui_message or '', default=default), error

Expand Down
20 changes: 10 additions & 10 deletions website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ def routes(app, database):
@app.route('/admin', methods=['GET'])
def get_admin_page():
if not utils.is_testing_request(request) and not is_admin(current_user()):
return utils.error_page(error=403, ui_message=gettext(u'unauthorized'))
return render_template('admin/admin.html', page_title=gettext(u'title_admin'))
return utils.error_page(error=403, ui_message=gettext('unauthorized'))
return render_template('admin/admin.html', page_title=gettext('title_admin'))


@app.route('/admin/users', methods=['GET'])
@requires_login
def get_admin_users_page(user):
if not is_admin(user):
return utils.error_page(error=403, ui_message=gettext(u'unauthorized'))
return utils.error_page(error=403, ui_message=gettext('unauthorized'))

category = request.args.get('filter', default=None, type=str)
category = None if category == "null" else category
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_admin_users_page(user):
user['index'] = counter
counter = counter + 1

return render_template('admin/admin-users.html', users=userdata, page_title=gettext(u'title_admin'),
return render_template('admin/admin-users.html', users=userdata, page_title=gettext('title_admin'),
filter=category, start_date=start_date, end_date=end_date, email_filter=substring,
language_filter=language, keyword_language_filter=keyword_language,
program_count=DATABASE.all_programs_count(), user_count=DATABASE.all_users_count())
Expand All @@ -92,7 +92,7 @@ def get_admin_users_page(user):
@requires_login
def get_admin_classes_page(user):
if not is_admin(user):
return utils.error_page(error=403, ui_message=gettext(u'unauthorized'))
return utils.error_page(error=403, ui_message=gettext('unauthorized'))

# Retrieving the user for each class to find the "last_used" is expensive -> improve when we have 100+ classes
classes = [{
Expand All @@ -103,13 +103,13 @@ def get_admin_classes_page(user):
"last_used": utils.datetotimeordate(utils.mstoisostring(DATABASE.user_by_username(Class.get('teacher')).get('last_login')))} for Class in DATABASE.all_classes()]
classes = sorted(classes, key=lambda d: d['last_used'], reverse=True)

return render_template('admin/admin-classes.html', classes=classes, page_title=gettext(u'title_admin'))
return render_template('admin/admin-classes.html', classes=classes, page_title=gettext('title_admin'))

@app.route('/admin/adventures', methods=['GET'])
@requires_login
def get_admin_adventures_page(user):
if not is_admin(user):
return utils.error_page(error=403, ui_message=gettext(u'unauthorized'))
return utils.error_page(error=403, ui_message=gettext('unauthorized'))

adventures = [{
"id": adventure.get('id'),
Expand All @@ -121,12 +121,12 @@ def get_admin_adventures_page(user):
} for adventure in DATABASE.all_adventures()]
adventures = sorted(adventures, key=lambda d: d['date'], reverse=True)

return render_template('admin/admin-adventures.html', adventures=adventures, page_title=gettext(u'title_admin'))
return render_template('admin/admin-adventures.html', adventures=adventures, page_title=gettext('title_admin'))

@app.route('/admin/stats', methods=['GET'])
@requires_login
def get_admin_stats_page(user):
if not is_admin(user):
return utils.error_page(error=403, ui_message=gettext(u'unauthorized'))
return render_template('admin/admin-stats.html', page_title=gettext(u'title_admin'))
return utils.error_page(error=403, ui_message=gettext('unauthorized'))
return render_template('admin/admin-stats.html', page_title=gettext('title_admin'))

Loading

0 comments on commit 00a9d29

Please sign in to comment.