diff --git a/store/app.py b/store/app.py index 08b0b9bb..55b8241c 100644 --- a/store/app.py +++ b/store/app.py @@ -14,7 +14,7 @@ from flask import Flask, send_from_directory, render_template, session, redirect from flask_babel import Babel from flask_babel import gettext as _ from github import Github, InputGitAuthor -from .utils import get_catalog, get_wishlist, get_stars, get_app_md_and_screenshots +from .utils import get_locale, get_catalog, get_wishlist, get_stars, get_app_md_and_screenshots app = Flask(__name__, static_url_path='/assets', static_folder="assets") @@ -48,13 +48,6 @@ if config.get("DEBUG"): # This is the secret key used for session signing app.secret_key = config["COOKIE_SECRET"] -AVAILABLE_LANGUAGES = ["en"] + os.listdir("translations") - -def get_locale(): - # try to guess the language from the user accept - # header the browser transmits. We support de/fr/en in this - # example. The best match wins. - return request.accept_languages.best_match(AVAILABLE_LANGUAGES) babel = Babel(app, locale_selector=get_locale) @app.template_filter('localize') diff --git a/store/utils.py b/store/utils.py index 817772c8..08e9250e 100644 --- a/store/utils.py +++ b/store/utils.py @@ -5,6 +5,14 @@ import toml import subprocess import pycmarkgfm from emoji import emojize +from flask import request + + +AVAILABLE_LANGUAGES = ["en"] + os.listdir("translations") +def get_locale(): + # try to guess the language from the user accept + # The best match wins. + return request.accept_languages.best_match(AVAILABLE_LANGUAGES) def get_catalog(): @@ -104,9 +112,9 @@ def human_to_binary(size: str) -> int: def get_app_md_and_screenshots(app_folder, infos): - locale = "en" # FIXME, deduce locale code from request + locale = get_locale() - if os.path.exists(os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")): + if locale != "en" and os.path.exists(os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")): description_path = os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md") elif os.path.exists(os.path.join(app_folder, "doc", "DESCRIPTION.md")): description_path = os.path.join(app_folder, "doc", "DESCRIPTION.md") @@ -118,7 +126,7 @@ def get_app_md_and_screenshots(app_folder, infos): else: infos["full_description_html"] = infos['manifest']['description'][locale] - if os.path.exists(os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")): + if locale != "en" and os.path.exists(os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")): pre_install_path = os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md") elif os.path.exists(os.path.join(app_folder, "doc", "PRE_INSTALL.md")): pre_install_path = os.path.join(app_folder, "doc", "PRE_INSTALL.md")