[feat/flask] Reworked locales system to use separate .ini file for each language #5

Merged
Sweetbread merged 9 commits from feat/flask-locales-rework into feat/flask 2025-08-13 16:58:29 +02:00
Owner
No description provided.
Burer added 1 commit 2025-03-25 13:46:06 +01:00
Burer requested review from Sweetbread 2025-03-25 13:46:07 +01:00
Sweetbread requested changes 2025-04-02 23:48:29 +02:00
@@ -2,3 +1,4 @@
import os
from datetime import date
from configparser import ConfigParser
Owner

Extra whitespace

Extra whitespace
Author
Owner

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.

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.
Sweetbread marked this conversation as resolved
app.py Outdated
@@ -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)
Owner

I was going to use language key for language selector:

for l in ('en', 'ru', 'ge', ...): lang[l]['language']

How will you do this in your implementation?

I was going to use `language` key for language selector: ```py for l in ('en', 'ru', 'ge', ...): lang[l]['language'] ``` How will you do this in your implementation?
Author
Owner

Implemented in latest commits.
Now list of available languages and list of available pages on the website generates automatically, from list of locales files.

Implemented in latest commits. Now list of available languages and list of available pages on the website generates automatically, from list of locales files.
Sweetbread marked this conversation as resolved
@@ -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>
Owner

PEP8 says function attributes should set without spaces around:

a = 1
# but
func(a=1)
PEP8 says function attributes should set without spaces around: ```py a = 1 # but func(a=1) ```
Author
Owner

Probably fixed in last commits, left only in places like this:

return render_template(
    "index.html",
    loc_list = locales_list,
    locale   = locales_dict[lang],
    lang     = lang,
    year     = date.today().year,
    current  = request.endpoint,
)

As for me, in such cases, this variant have better readability.
But I can fix this also, if anyone disagree.

Probably fixed in last commits, left only in places like this: ```python return render_template( "index.html", loc_list = locales_list, locale = locales_dict[lang], lang = lang, year = date.today().year, current = request.endpoint, ) ``` As for me, in such cases, this variant have better readability. But I can fix this also, if anyone disagree.
Sweetbread marked this conversation as resolved
Burer added 1 commit 2025-05-24 10:41:48 +02:00
- Finished all locale pages
- Updated styles, fixed some mobile problems
- Updated texts on index page
- Fixed flask locales search error, now it throws 404
- Something else, that I already forgot
Burer added 4 commits 2025-06-05 08:28:07 +02:00
- delete obsolete images
- resort images by folders
- add proper alt= parameters and standartized closing to <img> tags
Now list of locales is autogenerated from locales .ini files, and each locale use shared template files
Sweetbread self-assigned this 2025-06-24 14:54:51 +02:00
Sweetbread requested changes 2025-07-22 18:08:43 +02:00
Sweetbread left a comment
Owner

You joined all templates for different languages. Now pages for them are different. Are you sure you want to unificate?

You joined all templates for different languages. Now pages for them are different. Are you sure you want to unificate?
app.py Outdated
@@ -11,1 +19,3 @@
print(locale)
def load_all_locales():
Owner

Extra whitespace

Extra whitespace
Sweetbread marked this conversation as resolved
app.py Outdated
@@ -12,0 +47,4 @@
1,
loc["code"]
)
)
Owner

I think, it is an overcomplicated code: better to sort all other language codes separately and then append to ['en', 'ru', 'es']

I think, it is an overcomplicated code: better to sort all other language codes separately and then append to `['en', 'ru', 'es']`
Author
Owner

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.

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.
Owner

I'll fix it in mainstream

I'll fix it in mainstream
Sweetbread marked this conversation as resolved
app.py Outdated
@@ -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
Owner

Extra whitespace

Extra whitespace
Sweetbread marked this conversation as resolved
app.py Outdated
@@ -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)
Owner

Maybe just redirect to en version? Or look at accept-language header and choose the most preferred

Maybe just redirect to en version? Or look at `accept-language` header and choose the most preferred
Sweetbread marked this conversation as resolved
app.py Outdated
@@ -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):
Owner

The code is duplicated. The only difference is a template name

The code is duplicated. The only difference is a template name
Sweetbread marked this conversation as resolved
@@ -0,0 +25,4 @@
<td class="td-description">
{{ locale['downloads']['%s-descr' % ext] }}
{% if ext == 'raw' %}
<span class="beta">BETA</span>
Owner

What's this?

What's this?
Author
Owner

UEFI image has BETA status, so this small badge informs user about this.
We decided to leave this in place when reworking website design.

UEFI image has BETA status, so this small badge informs user about this. We decided to leave this in place when reworking website design.
Sweetbread marked this conversation as resolved
Burer added 1 commit 2025-07-25 12:51:10 +02:00
Burer added 1 commit 2025-08-03 09:43:33 +02:00
Sweetbread requested changes 2025-08-10 22:25:46 +02:00
Sweetbread left a comment
Owner

Solve this and it's ready to merge

Solve this and it's ready to merge
app.py Outdated
@@ -9,0 +16,4 @@
# ---------- APP CONFIG ------------------------------------------------------
cp = ConfigParser()
Owner

Useless global var. Initialize it in load_all_locales function to not waste RAM

Useless global var. Initialize it in `load_all_locales` function to not waste RAM
Burer marked this conversation as resolved
app.py Outdated
@@ -12,0 +80,4 @@
# ---------- MAIN PAGES ------------------------------------------------------
@app.route("/favicon.ico")
Owner

I think, it's better to just add a link into head and provide link to this as a regular static. Also, what do you think about webp? Maybe add multiple links (to webp and to ico for fallback)?

I think, it's better to just add a `link` into `head` and provide link to this as a regular static. Also, what do you think about webp? Maybe add multiple `link`s (to `webp` and to `ico` for fallback)?
Author
Owner

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.

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.
Burer added 1 commit 2025-08-12 13:55:22 +02:00
Sweetbread merged commit d35be6568e into feat/flask 2025-08-13 16:58:29 +02:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: KolibriOS/kolibrios.org#5
No description provided.