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

This commit is contained in:
2025-03-25 14:45:21 +02:00
parent ab629e3709
commit 952796182d
11 changed files with 222 additions and 186 deletions

30
app.py
View File

@@ -1,14 +1,28 @@
from flask import Flask, render_template, request, url_for, redirect
import os
from datetime import date
from configparser import ConfigParser
locale = ConfigParser()
with open('locale.ini', encoding='utf-8') as f:
locale.read_file(f)
from flask import Flask, render_template, url_for, redirect
cp = ConfigParser()
app = Flask(__name__)
print(locale)
def load_all_locales():
locales = {}
locales_dir = 'locales'
for filename in os.listdir(locales_dir):
if filename.endswith('.ini'):
lang = os.path.splitext(filename)[0]
cp = ConfigParser()
with open(os.path.join(locales_dir, filename), encoding='utf-8') as f:
cp.read_file(f)
locales[lang] = {section: dict(cp[section]) for section in cp.sections()}
return locales
locales = load_all_locales()
@app.route("/")
def home():
@@ -16,11 +30,13 @@ def home():
@app.route("/<lang>")
def index(lang):
return render_template(f'{lang}.html', locale=locale, lang=lang, year=date.today().year) # TODO: Check for vulnerability
return render_template(f'{lang}.html', locale=locales[lang], lang=lang, year=date.today().year) # TODO: Check for vulnerability
@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)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)

View File

@@ -1,156 +0,0 @@
[ru]
language = Русский
kolibrios = КолибриОС
download = Скачать
downloading = Загрузка
forum = Форум
wiki = Вики
description = Официальный сайт KolibriOS
team = Команда КолибриОС
git[1] = КолибриОС перешла на Git!
git[2] = Ознакомьтесь с нашей новой, удобной для разработчиков инфраструктурой
img-descr = Образ дискеты
iso-descr = Образ LiveCD
distr-descr = Универсальный образ Flash/Multi-boot
raw-descr = Гибридный UEFI/BIOS образ
prev_rev = Предыдущие выпуски
all_rev = Все ночные сборки
screenshots = Скриншоты
download_choice = Какой выбрать?
download_help = Для новичка лучше всего подойдет LiveCD.\n \
\n\
По сравнению с LiveCD преимущество универсального образа в том, что вы можете сохранить изменения, сделанные в KolibriOS.\n\
\n\
Гибридный образ включает поддержку технологии UEFI, которая используется для загрузки системы на новых компьютерах и ноутбуках.
download_description[0] = На этой странице вы можете скачать ночные сборки дистрибутива.
Это означает, что они всегда содержат последние изменения в системе и,
следовательно, могут быть нестабильными. Все файлы сжаты с помощью
download_description[1] = распространяется под лицензией
download_description[2] = а исходный код доступен на нашем
download_description[3] = Git-сервере
[ru.title]
index = KolibriOS
download_page = KolibriOS - Загрузка
[ru.screenshots]
1 = Рабочий стол KolibriOS
2 = Демки
3 = Файловые менеджеры
4 = Сетевые приложения
5 = Игры
6 = Инструменты разработчика
[en]
language = English
kolibrios = KolibriOS
download = Download
downloading = Downloads
forum = Forum
wiki = Wiki
description =
team = KolibriOS Team
git[1] = KolibriOS moved to Git!
git[2] = Check our new developers-friendly infrastructure
img-descr = Floppy disk image
iso-descr = LiveCD image
distr-descr = Universal Flash/Multi-boot image
raw-descr = Hybrid UEFI/BIOS image
prev_rev = Previous releases
all_rev = All nightly builds
screenshots = Screenshots
download_choice = Which to choose?
download_help = For a beginner, the LiveCD is best.\n\
\n\
Compared to a LiveCD, the advantage of a universal image is that you can save changes made in KolibriOS.\n\
\n\
Hybrid image includes support for UEFI technology, which is used to boot the system on new computers and laptops.
download_description[0] = On this page you can download the nightly builds distribution, which means
that they always contain the most recent changes in the system and can,
therefore, be unstable. All files are compressed with
download_description[1] = is distributed under
download_description[2] = license, its source code is available on our
download_description[3] = Git server
[en.title]
index = KolibriOS
download_page = KolibriOS - Download
[en.screenshots]
1 = KolibriOS desktop
2 = Demos
3 = File managers
4 = Network programs
5 = Games
6 = Developer and debug tools
[de]
language = Deutsch
kolibrios = KolibriOS
download = Herunterladen
downloading = Herunterladen
forum = Forum
wiki = Wiki
description =
team = KolibriOS Team
git[1] = KolibriOS ist zu Git gewechselt!
git[2] = Schau dir unsere neue entwicklerfreundliche Infrastruktur an
img-descr = Disketten-Image
iso-descr = LiveCD-Abbild
distr-descr = Universal Flash/Multi-Boot-Abbild
raw-descr = Hybrides UEFI/BIOS-Abbild
prev_rev = Frühere Versionen
all_rev = Alle nächtlichen Builds
screenshots = Bildschirmfotos
download_choice = Was soll ich wählen?
download_help = For a beginner, the LiveCD is best.\n\
\n\
Compared to a LiveCD, the advantage of a universal image is that you can save changes made in KolibriOS.\n\
\n\
Hybrid image includes support for UEFI technology, which is used to boot the system on new computers and laptops.
download_description[0] = Auf dieser Seite können Sie die nächtlichen Build-Distributionen herunterladen,
was bedeutet, dass sie stets die neuesten Änderungen am System enthalten und
daher instabil sein können. Alle Dateien sind mit
download_description[1] = komprimiert.
download_description[2] = wird unter der
download_description[3] =
[de.title]
index = KolibriOS
download_page = KolibriOS - Herunterladen
[de.screenshots]
1 = KolibriOS Arbeitsoberfläche
2 = Demos
3 = Datei-Manager
4 = Netzwerk-Programme
5 = Spiele
6 = Entwickler- und Debug-Tools

60
locales/de.ini Normal file
View File

@@ -0,0 +1,60 @@
[title]
language = Deutsch
index = KolibriOS
download_page = KolibriOS - Herunterladen
[header]
index = KolibriOS offizielle seite
download = KolibriOS Herunterladen
description = KolibriOS offizielle seite
[menu]
kolibrios = KolibriOS
download = Herunterladen
forum = Forum
wiki = Wiki
git = Git
[git]
header = KolibriOS ist zu Git gewechselt!
text = Schau dir unsere neue entwicklerfreundliche Infrastruktur an
[downloads]
header = Herunterladen
img-descr = Disketten-Image
iso-descr = LiveCD-Abbild
distr-descr = Universal Flash/Multi-Boot-Abbild
raw-descr = Hybrides UEFI/BIOS-Abbild
prev_rev = Frühere Versionen
all_rev = Alle nächtlichen Builds
screenshots = Bildschirmfotos
download_choice = Was soll ich wählen?
download_help = Für einen Einsteiger ist die LiveCD am besten geeignet.\n\
\n\
Im Vergleich zu einer LiveCD hat ein universelles Image den Vorteil, dass Sie die in KolibriOS vorgenommenen Änderungen speichern können.\n\
\n\
Das Hybrid-Image enthält Unterstützung für die UEFI-Technologie, die zum Booten des Systems auf neuen Computern und Laptops verwendet wird.
download_description[0] = Auf dieser Seite können Sie die nächtlichen Build-Distributionen herunterladen,
was bedeutet, dass sie stets die neuesten Änderungen am System enthalten und
daher instabil sein können. Alle Dateien sind mit
download_description[1] = komprimiert.
download_description[2] = wird unter der
download_description[3] = Git-Server
[screenshots]
header = Bildschirmfotos
1 = KolibriOS Arbeitsoberfläche
2 = Demos
3 = Datei-Manager
4 = Netzwerk-Programme
5 = Spiele
6 = Entwickler- und Debug-Tools
[footer]
team = KolibriOS-Team

58
locales/en.ini Normal file
View File

@@ -0,0 +1,58 @@
[title]
language = English
index = KolibriOS
download_page = KolibriOS - Download
[header]
index = KolibriOS official site
download = KolibriOS downloads
description = KolibriOS official site
[menu]
kolibrios = KolibriOS
download = Download
forum = Forum
wiki = Wiki
git = Git
[git]
header = KolibriOS moved to Git!
text = Check our new developers-friendly infrastructure
[downloads]
header = Downloads
img-descr = Floppy disk image
iso-descr = LiveCD image
distr-descr = Universal Flash/Multi-boot image
raw-descr = Hybrid UEFI/BIOS image
prev_rev = Previous releases
all_rev = All nightly builds
download_choice = Which to choose?
download_help = For a beginner, the LiveCD is best.\n\
\n\
Compared to a LiveCD, the advantage of a universal image is that you can save changes made in KolibriOS.\n\
\n\
Hybrid image includes support for UEFI technology, which is used to boot the system on new computers and laptops.
download_description[0] = On this page you can download the nightly builds distribution, which means
that they always contain the most recent changes in the system and can,
therefore, be unstable. All files are compressed with
download_description[1] = is distributed under
download_description[2] = license, its source code is available on our
download_description[3] = Git server
[screenshots]
header = Screenshots
1 = KolibriOS desktop
2 = Demos
3 = File managers
4 = Network programs
5 = Games
6 = Developer and debug tools
[footer]
team = KolibriOS Team

58
locales/ru.ini Normal file
View File

@@ -0,0 +1,58 @@
[title]
language = Русский
index = КолибриОС
download_page = КолибриОС - Скачать
[header]
index = Официальный сайт KolibriOS
download = Скачать КолибриОС
description = Официальный сайт KolibriOS
[menu]
kolibrios = КолибриОС
download = Скачать
forum = Форум
wiki = Вики
git = Гит
[git]
header = КолибриОС перешла на Гит!
text = Ознакомьтесь с нашей новой, удобной для разработчиков инфраструктурой
[downloads]
header = Скачать
img-descr = Образ дискеты
iso-descr = Образ LiveCD
distr-descr = Универсальный образ Flash/Multi-boot
raw-descr = Гибридный UEFI/BIOS образ
prev_rev = Предыдущие выпуски
all_rev = Все ночные сборки
download_choice = Какой выбрать?
download_help = Для новичка лучше всего подойдет LiveCD.\n \
\n\
По сравнению с LiveCD преимущество универсального образа в том, что вы можете сохранить изменения, сделанные в КолибриОС.\n\
\n\
Гибридный образ включает поддержку технологии UEFI, которая используется для загрузки системы на новых компьютерах и ноутбуках.
download_description[0] = На этой странице вы можете скачать ночные сборки дистрибутива.
Это означает, что они всегда содержат последние изменения в системе и,
следовательно, могут быть нестабильными. Все файлы сжаты с помощью
download_description[1] = распространяется под лицензией
download_description[2] = а исходный код доступен на нашем
download_description[3] = Git-сервере
[screenshots]
header = Скриншоты
1 = Рабочий стол КолибриОС
2 = Демки
3 = Файловые менеджеры
4 = Сетевые приложения
5 = Игры
6 = Инструменты разработчика
[footer]
team = Команда КолибриОС

View File

@@ -2,6 +2,6 @@
<img src="{{ url_for('static', filename='img/logo.png') }}" />
<p>
&copy; 2004{{ year }} <br />
{{ locale[lang]['team'] }}
{{ locale['footer']['team'] }}
</p>
</div>

View File

@@ -6,8 +6,8 @@
<img src="{{ url_for('static', filename='img/logo.png') }}" alt="Banner Image" />
</td>
<td valign="top">
<h1>{{ locale[lang]['git[1]'] }}</h1>
<p>{{ locale[lang]['git[2]'] }}</p>
<h1>{{ locale['git']['header'] }}</h1>
<p>{{ locale['git']['text'] }}</p>
<p class="p-link">
<a href="https://git.kolibrios.org">https://git.kolibrios.org</a>
</p>

View File

@@ -1,8 +1,8 @@
<head>
<meta charset="utf-8">
<title>{{ locale['%s.title' % lang][request.url_rule.endpoint] }}</title>
<title>{{ locale['header'][request.url_rule.endpoint] }}</title>
<link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
<meta name="description" content="{{ locale[lang]['description'] }}">
<meta name="description" content="{{ locale['header']['description'] }}">
<meta name="keywords"
content="kolibri, kolibrios, колибри, колибриос, colibri, operating system, assembler, калибри, fasm, alternate, open source">
<meta name="viewport" content="width=device-width">

View File

@@ -1,10 +1,10 @@
<nav id="menu">
<a href="{{ url_for('index', lang=lang) }}" class="a-sel">
<font bg="lightblue">{{ locale[lang]['kolibrios'] }}</font>
<font bg="lightblue">{{ locale['menu']['kolibrios'] }}</font>
</a>
<a href="{{ url_for('download_page', lang=lang) }}">{{ locale[lang]['download'] }}</a>
<a href="https://board.kolibrios.org">{{ locale[lang]['forum'] }}</a>
<a href="https://wiki.kolibrios.org/wiki/Main_Page/{{ lang }}">{{ locale[lang]['wiki'] }}</a>
<a href="{{ url_for('download_page', lang=lang) }}">{{ locale['menu']['download'] }}</a>
<a href="https://board.kolibrios.org">{{ locale['menu']['forum'] }}</a>
<a href="https://wiki.kolibrios.org/wiki/Main_Page/{{ lang }}">{{ locale['menu']['wiki'] }}</a>
<a href="https://git.kolibrios.org">Git</a>
<button onclick="dropdown_show(this)" id="lang-butt">
<img src="{{ url_for('static', filename='img/flags/%s.png' % lang) }}" alt="{{ lang }}">

View File

@@ -10,7 +10,7 @@
{% include 'tmpl/_menu.htm' %}
<div id="article">
<h1>{{ locale[lang]['downloading'] }}</h1>
<h1>{{ locale['downloads']['header'] }}</h1>
<table>
{% for ext, alt in (
('img', 'floppy'),
@@ -20,7 +20,7 @@
) %}
<tr class="tr-margin-bot">
<td class="td-image" width="40"><img src="{{ url_for('static', filename='img/icons/i_%s.png' % alt) }}" alt="{{ alt }}"></td>
<td class="td-description">{{ locale[lang]['%s-descr' % ext] }}</td>
<td class="td-description">{{ locale['downloads']['%s-descr' % ext] }}</td>
<td class="td-date">$autobuild_date_ru</td>
<td class="td-languages">
{% for l, lang in (
@@ -42,29 +42,29 @@
<tr class="tr-margin-top">
<td class="td-description" colspan="2">
<div role="button" class="help-button"
onclick="alert('{{ locale[lang]['download_help']}}');">
{{ locale[lang]['download_choice'] }}
onclick="alert('{{ locale.downloads.download_help }}');">
{{ locale['downloads']['download_choice'] }}
</div>
<td class="td-date">
<a href="//archive.kolibrios.org/ru/">{{ locale[lang]['prev_rev'] }}</a>
<a href="//archive.kolibrios.org/ru/">{{ locale['downloads']['prev_rev'] }}</a>
</td>
<td class="td-languages">
<a href="//builds.kolibrios.org/">{{ locale[lang]['all_rev'] }}</a>
<a href="//builds.kolibrios.org/">{{ locale['downloads']['all_rev'] }}</a>
</td>
</tr>
</table>
<p>
{{ locale[lang]['download_description[0]'] }}
{{ locale['downloads']['download_description[0]'] }}
<a href='http://www.7-zip.org' target='_blank'>7zip</a>.
<b>{{ locale[lang]['kolibrios'] }}</b> {{ locale[lang]['download_description[1]'] }}
<b>{{ locale['downloads']['kolibrios'] }}</b> {{ locale['downloads']['download_description[1]'] }}
<a href='http://www.gnu.org/licenses/gpl-2.0.html' target='_blank'>GPLv2</a>,
{{ locale[lang]['download_description[2]'] }}
<a href='https://git.kolibrios.org'>{{ locale[lang]['download_description[3]'] }}</a>.
{{ locale['downloads']['download_description[2]'] }}
<a href='https://git.kolibrios.org'>{{ locale['downloads']['download_description[3]'] }}</a>.
</p>
<h1>{{ locale[lang]['screenshots'] }}</h1>
<h1>{{ locale['screenshots']['header'] }}</h1>
<div id="screen" onclick="next()">
<div id="show">
@@ -73,7 +73,7 @@
id="slide{{ i }}"
src="{{ url_for('static', filename='img/screenshots/%d.png' % i ) }}"
{% if i == 1 %}class="visible"{% endif %}
alt="{{ locale['%s.screenshots' % lang]['%d' % i] }}" >
alt="{{ locale['screenshots']['%d' % i] }}" >
{% endfor %}
</div>
</div>