l10n: add the function of specifing date format, formatted the code
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 2m49s

This commit was merged in pull request #7.
This commit is contained in:
2026-01-18 07:39:21 +08:00
committed by Sweetbread
parent 9a99aa4f3b
commit ea969132f8
9 changed files with 28 additions and 9 deletions

17
app.py
View File

@@ -45,12 +45,16 @@ def before_request():
@app.context_processor
def _inject_autobuild_vers():
return {'autobuild_vers': autobuild.autobuild_vers}
return {"autobuild_vers": autobuild.autobuild_vers}
@app.context_processor
def _inject_autobuild_date():
return {'autobuild_date': autobuild.autobuild_date}
return {
"autobuild_date": g.translations.get("downloads", {})
.get("date-format", "{DD}.{MM}.{YYYY}")
.format(**autobuild.autobuild_date)
}
@app.context_processor
@@ -58,16 +62,19 @@ def inject_translations():
def translate(text, **kwargs):
section, key = text.split(":", 1)
template = g.translations \
.get(section, {}) \
template = (
g.translations.get(section, {})
.get(key, f"${section}: {key}$")
.replace("\\n", " \\n")
.replace("\n", "")
)
try:
return template.format(**kwargs)
except Exception:
return template
return {'_': translate}
return {"_": translate}
# ---------- ROUTES -------------------------------------------------------

View File

@@ -51,6 +51,7 @@ header = Herunterladen
version = Version:
date = Build-Datum:
date-format = {DD}.{MM}.{YYYY}
img-descr = Disketten-Image
iso-descr = LiveCD-Abbild

View File

@@ -49,6 +49,7 @@ header = Downloads
version = Version:
date = Build date:
date-format = {DD}/{MM}/{YYYY}
img-descr = Floppy disk image
iso-descr = LiveCD image

View File

@@ -51,6 +51,7 @@ header = Descargas
version = Versión:
date = Fecha de compilación:
date-format = {DD}.{MM}.{YYYY}
img-descr = Imagen de disquete
iso-descr = Imagen LiveCD

View File

@@ -51,6 +51,7 @@ header = Téléchargements
version = Version :
date = Date de compilation :
date-format = {DD}/{MM}/{YYYY}
img-descr = Image de la disquette
iso-descr = Image du LiveCD

View File

@@ -50,6 +50,7 @@ header = Scaricamento
version = Versione:
date = Data di compilazione:
date-format = {DD}/{MM}/{YYYY}
img-descr = Immagine su dischetto
iso-descr = Immagine LiveCD

View File

@@ -51,6 +51,7 @@ header = Downloads
version = Versie:
date = Builddatum:
date-format = {DD}.{MM}.{YYYY}
img-descr = Afbeelding op diskette
iso-descr = LiveCD-afbeelding

View File

@@ -51,6 +51,7 @@ header = Скачать
version = Версия:
date = Дата сборки:
date-format = {DD}.{MM}.{YYYY}
img-descr = Образ дискеты
iso-descr = Образ LiveCD

View File

@@ -6,7 +6,7 @@ import time
STATUS_URL = "https://builds.kolibrios.org/status.html"
STATUS_SEC = 300 # refetch each 5 minutes
autobuild_date = "DD.MM.YYYY"
autobuild_date = {"YYYY": "YYYY", "MM": "MM", "DD": "DD"}
autobuild_vers = "0.0.0.0+0000-0000000"
_started = False
@@ -56,12 +56,17 @@ def _refresh_build_date_once():
if not mts:
mds = re.search(r"\b(\d{2})\.(\d{2})\.(\d{4})\b", text)
if mds:
autobuild_date = f"{mds.group(1)}.{mds.group(2)}.{mds.group(3)}"
autobuild_date["YYYY"] = mds.group(1)
autobuild_date["MM"] = mds.group(2)
autobuild_date["DD"] = mds.group(3)
else:
return
else:
y, mo, d = mts.groups()
autobuild_date = f"{d}.{mo}.{y}"
(
autobuild_date["YYYY"],
autobuild_date["MM"],
autobuild_date["DD"],
) = mts.groups()
if last_commit_ver:
autobuild_vers = last_commit_ver