Dump JSON translations from translation form
This commit is contained in:
parent
9cbf356444
commit
bc23f2d1b8
@ -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)
|
||||
|
@ -10,7 +10,7 @@
|
||||
<h2>{{ language }}</h2>
|
||||
{% for string, translation in data.items() %}
|
||||
<label for="{{ string }}">{{ string }}</label>
|
||||
<input type="text" id="{{ string }}" value="{{ translation }}">
|
||||
<input type="text" id="{{ string }}" name="{{ string }}" value="{{ translation }}">
|
||||
<br>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
Loading…
Reference in New Issue
Block a user