l10n: add en and ru translation
This commit is contained in:
@@ -1,7 +1,55 @@
|
||||
from os import system as console
|
||||
from flask import Flask, render_template
|
||||
from configparser import ConfigParser
|
||||
from flask import (
|
||||
Flask,
|
||||
g,
|
||||
request,
|
||||
render_template,
|
||||
)
|
||||
# from flask_babel import Babel, _
|
||||
|
||||
|
||||
translations_cache = {}
|
||||
|
||||
def load_translations(lang):
|
||||
if lang not in translations_cache:
|
||||
try:
|
||||
config = ConfigParser()
|
||||
config.read(f'translations/{lang}.ini')
|
||||
translations_cache[lang] = dict(config['messages'])
|
||||
except:
|
||||
translations_cache[lang] = {}
|
||||
return translations_cache[lang]
|
||||
|
||||
|
||||
def get_locale():
|
||||
return request.accept_languages.best_match(('en', 'ru'), 'en')
|
||||
|
||||
app = Flask(__name__)
|
||||
# app.config['BABEL_DEFAULT_LOCALE'] = 'en'
|
||||
# app.config['BABEL_SUPPORTED_LOCALES'] = ['en', 'ru']
|
||||
# app.jinja_env.add_extension("jinja2.ext.i18n")
|
||||
# app.jinja_env.globals.update(_=lambda x: load_translations("ru")[x])
|
||||
|
||||
# babel = Babel(app, locale_selector=get_locale)
|
||||
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.locale = get_locale()
|
||||
g.translations = load_translations(g.locale)
|
||||
|
||||
|
||||
@app.context_processor
|
||||
def inject_translations():
|
||||
def translate(text, **kwargs):
|
||||
template = g.translations.get(text, f"${text}$")
|
||||
try:
|
||||
return template.format(**kwargs)
|
||||
except:
|
||||
return template
|
||||
return {'_': translate}
|
||||
|
||||
|
||||
if app.debug:
|
||||
console("sass static/style/main.scss static/style/main.css")
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
Flask==3.1.1
|
||||
Flask-Babel
|
||||
gunicorn
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<footer>
|
||||
<div>codrs.ru © 2025</div>
|
||||
<div><a href="https://g.codrs.ru/Sweetbread/codrs.ru">Исходники сайта</a></div>
|
||||
<div>Для связи: <a href="mailto:admin@codrs.ru">admin@codrs.ru</a></div>
|
||||
<div><a href="https://g.codrs.ru/Sweetbread/codrs.ru">{{ _('site source') }}</a></div>
|
||||
<div>{{ _('contact us') }}: <a href="mailto:admin@codrs.ru">admin@codrs.ru</a></div>
|
||||
</footer>
|
||||
@@ -1,8 +1,8 @@
|
||||
<header>
|
||||
<div class="header-links">
|
||||
{%- for (l, t) in (
|
||||
('us', 'О нас'),
|
||||
('host', 'О хосте')
|
||||
('us', _('about us')),
|
||||
('host', _('about host'))
|
||||
) %}
|
||||
{%- if url_for(l) == request.path %}
|
||||
<strong>{{ t }}</strong>
|
||||
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
{% extends 'base.tmpl' %}
|
||||
|
||||
{% block title %}О хосте{% endblock %}
|
||||
{% block title %}{{ _('about host') }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<a href="https://play2go.cloud/" target="_blank" class="block">
|
||||
<strong>Хостер</strong>: play2go
|
||||
<p>Неплохой, недорогой. В прошлом были проблемы с сетью</p>
|
||||
<strong>{{ _("hoster") }}</strong>: play2go
|
||||
<p>{{ _('hoster_descr') }}</p>
|
||||
</a>
|
||||
|
||||
<div class="block">
|
||||
<strong>Характеристики</strong>:
|
||||
<strong>{{ _("specifications") }}</strong>:
|
||||
<ul>
|
||||
<li>CPU: Ryzen i9</li>
|
||||
<li>RAM: 16 GiB</li>
|
||||
|
||||
+12
-6
@@ -11,20 +11,20 @@
|
||||
<img src="/static/icon/service/sharkey.webp" class="icon"/>
|
||||
<strong>Sharkey</strong>
|
||||
</div>
|
||||
<p>Федеративная микроблогинговая система поверх протокола ActivityPub</p>
|
||||
<p>{{ _('sharkey_descr') }}</p>
|
||||
</a>
|
||||
<a href="https://g.codrs.ru" target="_blank" class="block">
|
||||
<div class="header">
|
||||
<img src="/static/icon/service/gitea.webp" class="icon"/>
|
||||
<strong>Gitea</strong>
|
||||
</div>
|
||||
<p>Selfhosted хранилище git-репозиториев со свободным исходным кодом</p>
|
||||
<p>{{ _('gitea_descr') }}</p>
|
||||
</a>
|
||||
|
||||
<div class="block">
|
||||
<p><a href="https://m.codrs.ru" target="_blank"><strong>Matrix</strong></a> — федеративный мессанджер</p>
|
||||
<p><a href="https://c.codrs.ru" target="_blank"><strong>Copyparty</strong></a> — облачное хранилище файлов</p>
|
||||
<p><a href="https://s.codrs.ru" target="_blank"><strong>4get</strong></a> — прокси-поисковик</p>
|
||||
<p><a href="https://m.codrs.ru" target="_blank"><strong>Matrix</strong></a> — {{ _('matrix_descr') }}</p>
|
||||
<p><a href="https://c.codrs.ru" target="_blank"><strong>Copyparty</strong></a> — {{ _('copyparty_descr') }}</p>
|
||||
<p><a href="https://s.codrs.ru" target="_blank"><strong>4get</strong></a> — {{ _('4get_descr') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="block">
|
||||
@@ -43,6 +43,12 @@
|
||||
</div>
|
||||
|
||||
<div class="block">
|
||||
Ещё у нас есть <a href="https://bug.codrs.ru" target="_blank"><strong>GlitchTip</strong></a> и <a href="https://dav.codrs.ru" target="_blank"><strong>Baikal</strong></a> для участников нашей группы!
|
||||
{{
|
||||
_('bottom_text',
|
||||
glitchtip='<a href="https://bug.codrs.ru" target="_blank"><strong>GlitchTip</strong></a>',
|
||||
baikal='<a href="https://dav.codrs.ru" target="_blank"><strong>Baikal</strong></a>',
|
||||
freshrss='<a href="https://rss.codrs.ru" target="_blank"><strong>FreshRSS</strong></a>',
|
||||
) | safe
|
||||
}}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
[messages]
|
||||
site source = Site source
|
||||
contact us = Contact us
|
||||
|
||||
about us = About us
|
||||
about host = About host
|
||||
|
||||
hoster = Hoster
|
||||
|
||||
hoster_descr = Not bad, not expencive. There were network troubles in the past
|
||||
|
||||
specifications = Specifications
|
||||
|
||||
|
||||
sharkey_descr = Federative microbloging service under ActivityPub protocol
|
||||
gitea_descr = Opensource selfhosted git repository hosting
|
||||
matrix_descr = federative messenger
|
||||
copyparty_descr = cloud file storage
|
||||
4get_descr = proxy search engine
|
||||
|
||||
bottom_text = Also we have {glitchtip}, {baikal} and {freshrss} for members of our squad!
|
||||
@@ -0,0 +1,21 @@
|
||||
[messages]
|
||||
site source = Исходники сайта
|
||||
contact us = Для связи
|
||||
|
||||
about us = О нас
|
||||
about host = О хосте
|
||||
|
||||
hoster = Хостер
|
||||
|
||||
hoster_descr = Неплохой, недорогой. В прошлом были проблемы с сетью
|
||||
|
||||
specifications = Характеристики
|
||||
|
||||
|
||||
sharkey_descr = Федеративная микроблогинговая система поверх протокола ActivityPub
|
||||
gitea_descr = Selfhosted хранилище git-репозиториев со свободным исходным кодом
|
||||
matrix_descr = федеративный мессенджер
|
||||
copyparty_descr = облачное хранилище файлов
|
||||
4get_descr = прокси-поисковик
|
||||
|
||||
bottom_text = Ещё у нас есть {glitchtip}, {baikal} и {freshrss} для участников нашей группы!
|
||||
Reference in New Issue
Block a user