Translate the whole site to English: English routes with 301 redirects from the Dutch paths, English UI, docs, seeds and captions, one-time live content migration
This commit is contained in:
+48
-3
@@ -2,15 +2,22 @@
|
||||
import logging
|
||||
|
||||
from molodetz import config
|
||||
from molodetz.content import seed_placeholder_posts
|
||||
from molodetz.database import count_users, create_user, get_setting, get_user_by_username, set_setting
|
||||
from molodetz.content import LEGACY_SEED_TITLES, seed_placeholder_posts, translate_seeded_posts
|
||||
from molodetz.database import count_users, create_user, db, get_setting, get_user_by_username, set_setting
|
||||
from molodetz.gallery import sync_gallery
|
||||
from molodetz.utils.audit import record_system
|
||||
from molodetz.utils.auth import hash_password
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
ADMIN_BIO = "Begint de rol. Schrijft over het werk, het afmaken en het oordeel."
|
||||
ADMIN_BIO = "Starts the roll. Writes about the work, finishing it, and judgement."
|
||||
LEGACY_ADMIN_BIO = "Begint de rol. Schrijft over het werk, het afmaken en het oordeel."
|
||||
LEGACY_SETTINGS = {
|
||||
"site_tagline": ("De kring, niet de reclame.", "The circle, not the commercial."),
|
||||
"maintenance_message": ("Molodetz is even dicht voor onderhoud.", "Molodetz is closed for maintenance. Back shortly."),
|
||||
}
|
||||
LEGACY_NOTIFICATION_SUFFIXES = ((" wil meeschrijven", " wants to write along"),)
|
||||
LEGACY_NOTIFICATION_EXACT = {"Je API-sleutel is vernieuwd.": "Your API key was renewed."}
|
||||
|
||||
|
||||
def bootstrap_admin():
|
||||
@@ -26,9 +33,47 @@ def bootstrap_admin():
|
||||
|
||||
def bootstrap_content():
|
||||
admin = bootstrap_admin()
|
||||
migrate_to_english()
|
||||
if admin and get_setting("seed_posts_done", "0") != "1":
|
||||
created = seed_placeholder_posts(admin)
|
||||
set_setting("seed_posts_done", "1")
|
||||
record_system("post.seed", payload={"count": len(created)})
|
||||
synced = sync_gallery()
|
||||
logger.info("gallery synced: %d items", synced)
|
||||
|
||||
|
||||
def _translate_notification(message):
|
||||
if message in LEGACY_NOTIFICATION_EXACT:
|
||||
return LEGACY_NOTIFICATION_EXACT[message]
|
||||
if message.startswith("Gepubliceerd: "):
|
||||
title = message[len("Gepubliceerd: "):]
|
||||
return "Published: " + LEGACY_SEED_TITLES.get(title, title)
|
||||
if message.startswith("Back-up "):
|
||||
return "Backup " + message[len("Back-up "):].replace(" klaar", " finished").replace(" mislukt", " failed")
|
||||
for dutch, english in LEGACY_NOTIFICATION_SUFFIXES:
|
||||
if message.endswith(dutch):
|
||||
return message[: -len(dutch)] + english
|
||||
return message
|
||||
|
||||
|
||||
def migrate_to_english():
|
||||
if get_setting("content_language", "nl") == "en":
|
||||
return 0
|
||||
posts = translate_seeded_posts()
|
||||
for key, (dutch, english) in LEGACY_SETTINGS.items():
|
||||
if get_setting(key) == dutch or ("site_settings" in db.tables and (db["site_settings"].find_one(key=key) or {}).get("value") == dutch):
|
||||
set_setting(key, english)
|
||||
notes = 0
|
||||
if "notifications" in db.tables:
|
||||
for row in list(db["notifications"].all()):
|
||||
translated = _translate_notification(row.get("message") or "")
|
||||
if translated != row.get("message"):
|
||||
db["notifications"].update({"uid": row["uid"], "message": translated}, ["uid"])
|
||||
notes += 1
|
||||
if "users" in db.tables:
|
||||
for row in list(db["users"].find(bio=LEGACY_ADMIN_BIO)):
|
||||
db["users"].update({"uid": row["uid"], "bio": ADMIN_BIO}, ["uid"])
|
||||
set_setting("content_language", "en")
|
||||
record_system("system.migrate.english", payload={"posts": posts, "notifications": notes})
|
||||
logger.info("content migrated to english: %d posts, %d notifications", posts, notes)
|
||||
return posts
|
||||
|
||||
Reference in New Issue
Block a user