[feat/flask] Reworked locales system to use separate .ini file for each language #5
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/flask-locales-rework"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@@ -2,3 +1,4 @@
import os
from datetime import date
from configparser import ConfigParser
Extra whitespace
It is a common practice to separate groups of imports by empty line.
In this case, I decided to separate flask imports, as the main app component.
@@ -21,3 +35,3 @@
@app.route("/<lang>/download")
def download_page(lang):
return render_template('tmpl/download.htm', locale=locale, lang=lang)
return render_template('tmpl/download.htm', locale=locales[lang], lang=lang, year=date.today().year)
I was going to use
language
key for language selector:How will you do this in your implementation?
Implemented in latest commits.
Now list of available languages and list of available pages on the website generates automatically, from list of locales files.
@@ -18,3 +18,3 @@
</font>
{%- else %}
<a href="{{ url_for(request.url_rule.endpoint, lang=l) }}"><img src="{{ url_for('static', filename='img/flags/%s.png' % l) }}" alt='de'/>{{ lang }}</a>
<a href="{{ url_for(request.url_rule.endpoint, lang = l) }}"><img src="{{ url_for('static', filename='img/flags/%s.png' % l) }}" alt='de'/>{{ lang }}</a>
PEP8 says function attributes should set without spaces around:
Probably fixed in last commits, left only in places like this:
As for me, in such cases, this variant have better readability.
But I can fix this also, if anyone disagree.
You joined all templates for different languages. Now pages for them are different. Are you sure you want to unificate?
@@ -11,1 +19,3 @@
print(locale)
def load_all_locales():
Extra whitespace
@@ -12,0 +47,4 @@
1,
loc["code"]
)
)
I think, it is an overcomplicated code: better to sort all other language codes separately and then append to
['en', 'ru', 'es']
Didn't find a more succinct way to sort locales in required order.
Sorting them separately still requires two list comprehensions, or multi-line if/for blocks.
Would be glad if you prove me wrong.
I'll fix it in mainstream
@@ -17,3 +72,3 @@
@app.route("/<lang>")
def index(lang):
return render_template(f'{lang}.html', locale=locale, lang=lang, year=date.today().year) # TODO: Check for vulnerability
Extra whitespace
@@ -19,1 +74,3 @@
return render_template(f'{lang}.html', locale=locale, lang=lang, year=date.today().year) # TODO: Check for vulnerability
if lang not in locales_dict:
abort(404)
Maybe just redirect to en version? Or look at
accept-language
header and choose the most preferred@@ -21,3 +88,2 @@
@app.route("/<lang>/download")
def download_page(lang):
return render_template('tmpl/download.htm', locale=locale, lang=lang)
def download(lang):
The code is duplicated. The only difference is a template name
@@ -0,0 +25,4 @@
<td class="td-description">
{{ locale['downloads']['%s-descr' % ext] }}
{% if ext == 'raw' %}
<span class="beta">BETA</span>
What's this?
UEFI image has BETA status, so this small badge informs user about this.
We decided to leave this in place when reworking website design.
Solve this and it's ready to merge
@@ -9,0 +16,4 @@
# ---------- APP CONFIG ------------------------------------------------------
cp = ConfigParser()
Useless global var. Initialize it in
load_all_locales
function to not waste RAM@@ -12,0 +80,4 @@
# ---------- MAIN PAGES ------------------------------------------------------
@app.route("/favicon.ico")
I think, it's better to just add a
link
intohead
and provide link to this as a regular static. Also, what do you think about webp? Maybe add multiplelink
s (towebp
and toico
for fallback)?Removed redundant favicon route.
IMHO,
.webp
is not the best option here. From my frontend dev practice, it is not usually used for favicon. And moreover, if we replace any images on the website with.webp
- they couldn't be displayed in KolibriOS.