diff --git a/kanken_online/__init__.py b/kanken_online/__init__.py index 284616b..5c3c160 100644 --- a/kanken_online/__init__.py +++ b/kanken_online/__init__.py @@ -1,5 +1,6 @@ +import json import os -from flask import Flask, redirect, render_template, g, request, session +from flask import Flask, redirect, render_template, g, request, session, url_for from pathlib import Path from .auth import login_required @@ -74,21 +75,6 @@ def create_app(test_config=None): def kotoba_page(kotoba: str): return render_template("kotoba.html", kotoba=kotoba) - @app.route("/translations", methods=["GET", "POST"]) - def strings_translation(): - if request.method == "GET": - strings = {} - for language, language_data in lang.LANGUAGES.items(): - strings[language] = { - string: translation for string, translation in language_data.items() - } - - return render_template("translations.html", strings=strings) - else: - # TODO - print(request.form) - return redirect("/translations") - from . import database database.initialize_app(app) @@ -101,6 +87,26 @@ def create_app(test_config=None): from . import lang + @app.route("/translations", methods=["GET", "POST"]) + def strings_translation(): + if request.method == "GET": + strings = {} + for language, language_data in lang.LANGUAGES.items(): + strings[language] = { + string: translation for string, translation in language_data.items() + } + + return render_template("translations.html", strings=strings) + else: + strings = {} + for i, language in enumerate(lang.LANGUAGES): + strings[language] = { + string: request.form.getlist(string)[i] for string in request.form + } + with open(Path(app.root_path, "static", "lang", f"{language}.json"), mode="w") as f: + json.dump(strings[language], f, ensure_ascii=False, indent=0) + return redirect("/translations") + # def use_english(text_id: str): # return lang.localize(text_id, lang.JAPANESE) app.jinja_env.globals.update(localize=lang.localize) diff --git a/kanken_online/templates/translations.html b/kanken_online/templates/translations.html index 7d205b3..321ec3c 100644 --- a/kanken_online/templates/translations.html +++ b/kanken_online/templates/translations.html @@ -10,7 +10,7 @@

{{ language }}

{% for string, translation in data.items() %} - +
{% endfor %} {% endfor %}