l10n: add sections
This commit is contained in:
@@ -6,19 +6,22 @@ from flask import (
|
||||
request,
|
||||
render_template,
|
||||
)
|
||||
# from flask_babel import Babel, _
|
||||
|
||||
|
||||
translations_cache = {}
|
||||
|
||||
def load_translations(lang):
|
||||
if lang not in translations_cache:
|
||||
translations_cache[lang] = {}
|
||||
|
||||
try:
|
||||
config = ConfigParser()
|
||||
config.read(f'translations/{lang}.ini')
|
||||
translations_cache[lang] = dict(config['messages'])
|
||||
for section in config.sections():
|
||||
translations_cache[lang][section] = dict(config.items(section))
|
||||
except:
|
||||
translations_cache[lang] = {}
|
||||
pass
|
||||
|
||||
return translations_cache[lang]
|
||||
|
||||
|
||||
@@ -26,12 +29,6 @@ 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
|
||||
@@ -43,11 +40,20 @@ def before_request():
|
||||
@app.context_processor
|
||||
def inject_translations():
|
||||
def translate(text, **kwargs):
|
||||
template = g.translations.get(text, f"${text}$")
|
||||
if ":" in text:
|
||||
section, key = text.split(":", 1)
|
||||
else:
|
||||
section, key = "messages", text
|
||||
|
||||
template = g.translations \
|
||||
.get(section, {}) \
|
||||
.get(key, f"${section}: {key}$")
|
||||
|
||||
try:
|
||||
return template.format(**kwargs)
|
||||
except:
|
||||
return template
|
||||
|
||||
return {'_': translate}
|
||||
|
||||
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
<img src="/static/icon/service/sharkey.webp" class="icon"/>
|
||||
<strong>Sharkey</strong>
|
||||
</div>
|
||||
<p>{{ _('sharkey_descr') }}</p>
|
||||
<p>{{ _('index.descr:sharkey') }}</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>{{ _('gitea_descr') }}</p>
|
||||
<p>{{ _('index.descr:gitea') }}</p>
|
||||
</a>
|
||||
|
||||
<div class="block">
|
||||
<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>
|
||||
<p><a href="https://m.codrs.ru" target="_blank"><strong>Matrix</strong></a> — {{ _('index.descr:matrix') }}</p>
|
||||
<p><a href="https://c.codrs.ru" target="_blank"><strong>Copyparty</strong></a> — {{ _('index.descr:copyparty') }}</p>
|
||||
<p><a href="https://s.codrs.ru" target="_blank"><strong>4get</strong></a> — {{ _('index.descr:4get') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="block">
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
<div class="block">
|
||||
{{
|
||||
_('bottom_text',
|
||||
_('index: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>',
|
||||
|
||||
+14
-12
@@ -5,17 +5,19 @@ 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
|
||||
|
||||
[index]
|
||||
bottom_text = Also we have {glitchtip}, {baikal} and {freshrss} for members of our squad!
|
||||
|
||||
[index.descr]
|
||||
sharkey = Federative microbloging service under ActivityPub protocol
|
||||
gitea = Opensource selfhosted git repository hosting
|
||||
matrix = federative messenger
|
||||
copyparty = cloud file storage
|
||||
4get = proxy search engine
|
||||
|
||||
|
||||
[host]
|
||||
hoster = Hoster
|
||||
specifications = Specifications
|
||||
hoster_descr = Not bad, not expencive. There were network troubles in the past
|
||||
|
||||
+14
-12
@@ -5,17 +5,19 @@ contact us = Для связи
|
||||
about us = О нас
|
||||
about host = О хосте
|
||||
|
||||
hoster = Хостер
|
||||
|
||||
hoster_descr = Неплохой, недорогой. В прошлом были проблемы с сетью
|
||||
|
||||
specifications = Характеристики
|
||||
|
||||
|
||||
sharkey_descr = Федеративная микроблогинговая система поверх протокола ActivityPub
|
||||
gitea_descr = Selfhosted хранилище git-репозиториев со свободным исходным кодом
|
||||
matrix_descr = федеративный мессенджер
|
||||
copyparty_descr = облачное хранилище файлов
|
||||
4get_descr = прокси-поисковик
|
||||
|
||||
[index]
|
||||
bottom_text = Ещё у нас есть {glitchtip}, {baikal} и {freshrss} для участников нашей группы!
|
||||
|
||||
[index.descr]
|
||||
sharkey = Федеративная микроблогинговая система поверх протокола ActivityPub
|
||||
gitea = Selfhosted хранилище git-репозиториев со свободным исходным кодом
|
||||
matrix = федеративный мессенджер
|
||||
copyparty = облачное хранилище файлов
|
||||
4get = прокси-поисковик
|
||||
|
||||
|
||||
[host]
|
||||
hoster = Хостер
|
||||
specifications = Характеристики
|
||||
hoster_descr = Неплохой, недорогой. В прошлом были проблемы с сетью
|
||||
|
||||
Reference in New Issue
Block a user