'How to internationalize data from DB - dynamic values
I've succeeded in translating my app into multiple language but I've got problems with all the datas coming from my db and also modals.
Does anyone have a solution.
For example where {{day}} and day_in_select in all_days are datas from DB.
name="day"
onchange="this.form.submit()"
>
{% if day %}
<option value="{{day}}">{{day}}</option>
{% endif %}
<option value="">{{allDays}}</option>
{% for day_in_select in all_days | sort(attribute="order")
%}
<option value="{{day_in_select.day}}">
{{day_in_select.day}}
</option>
{% endfor %}
</select>
Thanks for your answers.
I am using only json templates to get my translations done, not any .po
files are used. Also I don't do updates. The translations clicks are done from this code:
@app.route("/language=<language>")
def set_language(language=None):
session["language"] = language
locale.setlocale(locale.LC_ALL, language)
return redirect(url_for("dashboard"))
@babel.localeselector
def get_locale():
if request.args.get("language"):
session["language"] = request.args.get("language")
return session["language"]
app.config["LANGUAGES"] = {
"en_US": "English",
"fr_FR": "French",
}
@app.context_processor
def inject_conf_var():
return dict(
AVAILABLE_LANGUAGES=app.config["LANGUAGES"],
CURRENT_LANGUAGE=session.get(
"language",
request.accept_languages.best_match(app.config["LANGUAGES"].keys()),
),
)
if __name__ == "app":
app_language = "fr_FR"
locale.setlocale(locale.LC_ALL, app_language)
languages = {}
# language_list = glob.glob("translations/*.json")
language_list = [
"en_US",
"fr_FR",
]
for lang in language_list:
l = "translations/" + lang + ".json"
code = lang
with open(l, "r", encoding="utf8") as file:
languages[code] = json.loads(file.read())
If anyone has suggestions, let me know.
Thanks so much Chabelle
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|