* Added class for internationalization to the project * Added English and German language files * Moved all strings to the language files * Translated to German * Added context processor to inject language file into every templateprojects
parent
ad8f68cdd8
commit
1e3ce054a9
11 changed files with 338 additions and 86 deletions
@ -0,0 +1,50 @@ |
|||||||
|
{ |
||||||
|
"html_language": "de", |
||||||
|
"browser_language": "de-DE", |
||||||
|
"ok": "ok", |
||||||
|
"cancel": "abbrechen", |
||||||
|
"dashboard": "dashboard", |
||||||
|
"username": "benutzername", |
||||||
|
"password": "passwort", |
||||||
|
"login": "login", |
||||||
|
"logout": "abmelden", |
||||||
|
"comments": "kommentare", |
||||||
|
"unpublished": "unveröffentlicht", |
||||||
|
"published": "veröffentlicht", |
||||||
|
"spam": "spam", |
||||||
|
"edit": "editieren", |
||||||
|
"manage": "verwalten", |
||||||
|
"export": "export", |
||||||
|
"delete": "löschen", |
||||||
|
"new": "neu", |
||||||
|
"project": "projekt", |
||||||
|
"new_project": "neues projekt", |
||||||
|
"statistics": "statistiken", |
||||||
|
"address": "adresse", |
||||||
|
"status": "status", |
||||||
|
"manage_mail": "Mail Addressen verwalten", |
||||||
|
"manage_comments": "Kommentare verwalten", |
||||||
|
"manage_comments_delete_comment": "Diesen Kommentar löschen", |
||||||
|
"manage_comments_delete_and_block": "Diesen Kommentar löschen und EMail Adresse blocken.", |
||||||
|
"manage_comments_allow_comment": "Diesen Kommentar erlauben, aber Email Adresse nicht freischalten.", |
||||||
|
"manage_comments_allow_and_approve": "Diesen Kommentar erlauben und Email Adresse freischalten.", |
||||||
|
"manage_spam": "Spam verwalten", |
||||||
|
"select_article": "Artikel auswählen", |
||||||
|
"hooray_no_spam": "Hurra, kein Spam!", |
||||||
|
"spam_score": "Spamerkennung", |
||||||
|
"tooltip_spam_score": "Je höher der Spam Wert ist, desto höher die Chance, dass es sich um Spam handelt.", |
||||||
|
"stats_label_regular_comments": "reguläre Kommentare", |
||||||
|
"stats_label_unpublished_comments": "unveröffentlichte Kommentare", |
||||||
|
"stats_last_7_days": "Aktivität der letzten 7 Tage", |
||||||
|
"stats_total_percentage": "Verhältnis von Kommentaren zu Spam", |
||||||
|
"select_project_to_manage": "Projekte:", |
||||||
|
"tooltip_create_new_project": "Neues Projekt erzeugen", |
||||||
|
"tooltip_delete_project": "Projekt und dazugehörige Daten löschen", |
||||||
|
"tooltip_edit_project": "Einstellungen und Daten des Projekts ändern", |
||||||
|
"tooltip_export_all_comments": "Alle Kommentare nach Hugo exportieren.<br>Wird normalerweise nicht benötigt.", |
||||||
|
"tooltip_manage_this_project": "Dieses Projekt verwalten", |
||||||
|
"placeholder_search_mail": "Mail Adressen durchsuchen", |
||||||
|
"tooltip_email_blocked": "Email ist momentan gesperrt. Zum entsperren klicken.", |
||||||
|
"tooltip_email_allowed": "Email darf momentan ohne Bestätigung posten. Zum Sperren klicken.", |
||||||
|
"tooltip_delete_email": "Eintrag löschen. Email unterliegt wieder den normalen Regeln." |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
{ |
||||||
|
"html_language": "en", |
||||||
|
"browser_language": "en-US", |
||||||
|
"ok": "ok", |
||||||
|
"cancel": "cancel", |
||||||
|
"dashboard": "dashboard", |
||||||
|
"username": "username", |
||||||
|
"password": "password", |
||||||
|
"login": "login", |
||||||
|
"logout": "logout", |
||||||
|
"comments": "comments", |
||||||
|
"unpublished": "unpublished", |
||||||
|
"published": "published", |
||||||
|
"spam": "spam", |
||||||
|
"edit": "edit", |
||||||
|
"manage": "manage", |
||||||
|
"export": "export", |
||||||
|
"delete": "delete", |
||||||
|
"new": "new", |
||||||
|
"project": "project", |
||||||
|
"new_project": "new project", |
||||||
|
"statistics": "statistics", |
||||||
|
"address": "address", |
||||||
|
"status": "status", |
||||||
|
"manage_mail": "manage mail addresses", |
||||||
|
"stats_label_regular_comments": "regular comments", |
||||||
|
"stats_label_unpublished_comments": "unpublished comments", |
||||||
|
"stats_last_7_days": "Activity last 7 days", |
||||||
|
"stats_total_percentage": "Total comment - spam ratio", |
||||||
|
"manage_comments": "manage comments", |
||||||
|
"manage_comments_delete_comment": "Delete this comment", |
||||||
|
"manage_comments_delete_and_block": "Delete this comment and block mail address", |
||||||
|
"manage_comments_allow_comment": "Approve this comment, don't approve mail", |
||||||
|
"manage_comments_allow_and_approve": "Approve this comment and approve mail", |
||||||
|
"select_article": "Select article", |
||||||
|
"select_project_to_manage": "Projects", |
||||||
|
"hooray_no_spam": "Hooray, no Spam!", |
||||||
|
"spam_score": "score", |
||||||
|
"tooltip_spam_score": "The higher the spam score is, the more likely it is spam", |
||||||
|
"tooltip_create_new_project": "Create a new project", |
||||||
|
"tooltip_delete_project": "Delete the project and all of its content", |
||||||
|
"tooltip_edit_project": "Edit the name of the project and it's properties", |
||||||
|
"tooltip_export_all_comments": "Export all comments to Hugo.<br>This is normally not needed.", |
||||||
|
"tooltip_manage_this_project": "Manage this project", |
||||||
|
"placeholder_search_mail": "Search mail", |
||||||
|
"tooltip_email_blocked": "Email is currently blocked. Click to unblock.", |
||||||
|
"tooltip_email_allowed": "Email is currently excempt from spam detection. Click to block.", |
||||||
|
"tooltip_delete_email": "Delete entry, Email has to follow the regular rules." |
||||||
|
} |
@ -0,0 +1,47 @@ |
|||||||
|
#!/usr/bin/env python3 |
||||||
|
# -*- coding: utf-8 -*- |
||||||
|
# /********************************************************************************** |
||||||
|
# * _author : Domeniko Gentner |
||||||
|
# * _mail : code@tuxstash.de |
||||||
|
# * _repo : https://git.tuxstash.de/gothseidank/labertasche |
||||||
|
# * _license : This project is under MIT License |
||||||
|
# *********************************************************************************/ |
||||||
|
from flask import Request |
||||||
|
from pathlib import Path |
||||||
|
from json import load |
||||||
|
|
||||||
|
|
||||||
|
class Language: |
||||||
|
|
||||||
|
def __init__(self, request: Request): |
||||||
|
# Define data |
||||||
|
self.i18n = dict() |
||||||
|
self.languages = list() |
||||||
|
|
||||||
|
# Directory where translations live |
||||||
|
i18n_dir = Path('./i18n').absolute() |
||||||
|
|
||||||
|
# Looks for translations |
||||||
|
for filename in i18n_dir.glob("*.json"): |
||||||
|
if filename.is_file(): |
||||||
|
self.languages.append(filename.stem) |
||||||
|
|
||||||
|
# Check the browser language in the headers |
||||||
|
self.browser_language = request.accept_languages.best_match(self.languages, default="en-US") |
||||||
|
|
||||||
|
# Try to Load language accepted by browser |
||||||
|
try: |
||||||
|
file = i18n_dir / self.browser_language |
||||||
|
with file.with_suffix(".json").absolute().open('r', encoding='utf-8') as fp: |
||||||
|
foreign = load(fp) |
||||||
|
except FileNotFoundError: |
||||||
|
pass |
||||||
|
|
||||||
|
# Always load english |
||||||
|
file = i18n_dir / "en-US" |
||||||
|
with file.with_suffix(".json").absolute().open('r', encoding='utf-8') as fp: |
||||||
|
self.i18n = load(fp) |
||||||
|
|
||||||
|
# Merge dicts, so missing keys are replaced with English |
||||||
|
self.i18n.update(**foreign) |
||||||
|
|
Loading…
Reference in new issue