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
61
searx/user_help/__init__.py
Normal file
61
searx/user_help/__init__.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
from typing import Dict
|
||||
import os.path
|
||||
import pkg_resources
|
||||
|
||||
import flask
|
||||
from flask.helpers import url_for
|
||||
import mistletoe
|
||||
|
||||
from .. import get_setting
|
||||
from ..version import GIT_URL
|
||||
from ..locales import LOCALE_NAMES
|
||||
|
||||
HELP: Dict[str, str] = {}
|
||||
""" Maps a filename under help/ without the file extension to the rendered HTML. """
|
||||
|
||||
|
||||
def render(app: flask.Flask):
|
||||
"""
|
||||
Renders the user documentation. Must be called after all Flask routes have been
|
||||
registered, because the documentation might try to link to them with Flask's `url_for`.
|
||||
|
||||
We render the user documentation once on startup to improve performance.
|
||||
"""
|
||||
|
||||
link_targets = {
|
||||
'brand.git_url': GIT_URL,
|
||||
'brand.public_instances': get_setting('brand.public_instances'),
|
||||
'brand.docs_url': get_setting('brand.docs_url'),
|
||||
}
|
||||
|
||||
base_url = get_setting('server.base_url') or None
|
||||
# we specify base_url so that url_for works for base_urls that have a non-root path
|
||||
|
||||
with app.test_request_context(base_url=base_url):
|
||||
link_targets['url_for:index'] = url_for('index')
|
||||
link_targets['url_for:preferences'] = url_for('preferences')
|
||||
link_targets['url_for:stats'] = url_for('stats')
|
||||
|
||||
define_link_targets = ''.join(f'[{name}]: {url}\n' for name, url in link_targets.items())
|
||||
|
||||
for locale_name in pkg_resources.resource_listdir(__name__, '.'):
|
||||
if locale_name not in LOCALE_NAMES:
|
||||
continue
|
||||
HELP[locale_name] = {}
|
||||
for filename in pkg_resources.resource_listdir(__name__, locale_name):
|
||||
rootname, ext = os.path.splitext(filename)
|
||||
|
||||
if ext != '.md':
|
||||
continue
|
||||
|
||||
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
|
||||
71
searx/user_help/en/about.md
Normal file
71
searx/user_help/en/about.md
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# About [searxng][url_for:index]
|
||||
|
||||
SearXNG is a fork from the well-known [searx] [metasearch engine], aggregating
|
||||
the results of other [search engines][url_for:preferences] while not storing
|
||||
information about its users.
|
||||
|
||||
More about SearXNG ...
|
||||
|
||||
* [SearXNG sources][brand.git_url]
|
||||
* [weblate]
|
||||
|
||||
---
|
||||
|
||||
## Why use it?
|
||||
|
||||
* SearXNG may not offer you as personalised results as Google,
|
||||
but it doesn't generate a profile about you.
|
||||
|
||||
* SearXNG doesn't care about what you search for, never shares anything
|
||||
with a third party, and it can't be used to compromise you.
|
||||
|
||||
* SearXNG is free software, the code is 100% open and you can help
|
||||
to make it better. See more on [SearXNG sources][brand.git_url].
|
||||
|
||||
If you do care about privacy, want to be a conscious user, or otherwise
|
||||
believe in digital freedom, make SearXNG your default search engine or run
|
||||
it on your own server
|
||||
|
||||
## Technical details - How does it work?
|
||||
|
||||
SearXNG is a [metasearch engine], inspired by the [seeks project]. It provides
|
||||
basic privacy by mixing your queries with searches on other platforms without
|
||||
storing search data. Queries are made using a POST request on every browser
|
||||
(except Chromium-based browsers*). Therefore they show up in neither our logs,
|
||||
nor your url history. In the case of Chromium-based browser users there is an
|
||||
exception: searx uses the search bar to perform GET requests. SearXNG can be
|
||||
added to your browser's search bar; moreover, it can be set as the default
|
||||
search engine.
|
||||
|
||||
<span id='add to browser'></span>
|
||||
## How to set as the default search engine?
|
||||
|
||||
SearXNG supports [OpenSearch]. For more information on changing your default
|
||||
search engine, see your browser's documentation:
|
||||
|
||||
* [Firefox](https://support.mozilla.org/en-US/kb/add-or-remove-search-engine-firefox)
|
||||
* [Microsoft Edge](https://support.microsoft.com/en-us/help/4028574/microsoft-edge-change-the-default-search-engine)
|
||||
* Chromium-based browsers [only add websites that the user navigates to without a path.](https://www.chromium.org/tab-to-search)
|
||||
|
||||
## Where to find anonymous usage statistics of this instance ?
|
||||
|
||||
[Stats page][url_for:stats] contains some useful data about the engines used.
|
||||
|
||||
## How can I make it my own?
|
||||
|
||||
SearXNG appreciates your concern regarding logs, so take the code from
|
||||
the [SearXNG project][brand.git_url] and run it yourself!
|
||||
|
||||
Add your instance to this [list of public instances][brand.public_instances] to
|
||||
help other people reclaim their privacy and make the Internet freer! The more
|
||||
decentralized the Internet is, the more freedom we have!
|
||||
|
||||
## Where are the docs & code of this instance?
|
||||
|
||||
See the [SearXNG docs][brand.docs_url] and [SearXNG sources][brand.git_url]
|
||||
|
||||
[searx]: https://github.com/searx/searx
|
||||
[metasearch engine]: https://en.wikipedia.org/wiki/Metasearch_engine
|
||||
[weblate]: https://weblate.bubu1.eu/projects/searxng/
|
||||
[seeks project]: https://beniz.github.io/seeks/
|
||||
[OpenSearch]: https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md
|
||||
Loading…
Add table
Add a link
Reference in a new issue