mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
[mod] user_help: support translations
replace "user_help.HELP" by a new function "get_help_for_locale". This function the help a one locale, and fall back to English if the translation is not available.
This commit is contained in:
parent
6a366c9807
commit
86628a935d
3 changed files with 23 additions and 10 deletions
|
@ -6,8 +6,9 @@ import flask
|
||||||
from flask.helpers import url_for
|
from flask.helpers import url_for
|
||||||
import mistletoe
|
import mistletoe
|
||||||
|
|
||||||
from . import get_setting
|
from .. import get_setting
|
||||||
from .version import GIT_URL
|
from ..version import GIT_URL
|
||||||
|
from ..locales import LOCALE_NAMES
|
||||||
|
|
||||||
HELP: Dict[str, str] = {}
|
HELP: Dict[str, str] = {}
|
||||||
""" Maps a filename under help/ without the file extension to the rendered HTML. """
|
""" Maps a filename under help/ without the file extension to the rendered HTML. """
|
||||||
|
@ -37,12 +38,24 @@ def render(app: flask.Flask):
|
||||||
|
|
||||||
define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items())
|
define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items())
|
||||||
|
|
||||||
for filename in pkg_resources.resource_listdir(__name__, 'help'):
|
for locale_name in pkg_resources.resource_listdir(__name__, '.'):
|
||||||
rootname, ext = os.path.splitext(filename)
|
if locale_name not in LOCALE_NAMES:
|
||||||
|
|
||||||
if ext != '.md':
|
|
||||||
continue
|
continue
|
||||||
|
HELP[locale_name] = {}
|
||||||
|
for filename in pkg_resources.resource_listdir(__name__, locale_name):
|
||||||
|
rootname, ext = os.path.splitext(filename)
|
||||||
|
|
||||||
markdown = pkg_resources.resource_string(__name__, 'help/' + filename).decode()
|
if ext != '.md':
|
||||||
markdown = define_link_targets + markdown
|
continue
|
||||||
HELP[rootname] = mistletoe.markdown(markdown)
|
|
||||||
|
markdown = pkg_resources.resource_string(__name__, locale_name + '/' + filename).decode()
|
||||||
|
markdown = define_link_targets + markdown
|
||||||
|
HELP[locale_name][rootname] = mistletoe.markdown(markdown)
|
||||||
|
|
||||||
|
|
||||||
|
def get_help_for_locale(locale_name: str) -> Dict[str, str]:
|
||||||
|
result = {**HELP['en']}
|
||||||
|
if locale_name != 'en':
|
||||||
|
for rootname, content in HELP.get(locale_name, {}).items():
|
||||||
|
result[rootname] = content
|
||||||
|
return result
|
|
@ -878,7 +878,7 @@ def __get_translated_errors(unresponsive_engines: Iterable[UnresponsiveEngine]):
|
||||||
@app.route('/about', methods=['GET'])
|
@app.route('/about', methods=['GET'])
|
||||||
def about():
|
def about():
|
||||||
"""Render about page"""
|
"""Render about page"""
|
||||||
return render('about.html', help=user_help.HELP)
|
return render('about.html', help=user_help.get_help_for_locale(get_locale()))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/autocompleter', methods=['GET', 'POST'])
|
@app.route('/autocompleter', methods=['GET', 'POST'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue