mirror of
https://github.com/kaaninchen/Gleiswechsel.git
synced 2026-09-17 16:52:47 +00:00
transitous rewrite: multiple languages support
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
# generated by datamodel-codegen:
|
||||
# filename: de.yaml
|
||||
# timestamp: 2026-08-17T18:44:37+00:00
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class LongName:
|
||||
train_from: str
|
||||
train_via: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Channel:
|
||||
status: str
|
||||
long_name: LongName
|
||||
|
||||
|
||||
@dataclass
|
||||
class Footer:
|
||||
notice: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Info:
|
||||
description: str
|
||||
via: str
|
||||
via_and: str
|
||||
next_stop: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class EndOfConnection:
|
||||
message: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Announcement:
|
||||
title: str
|
||||
end_of_connection: EndOfConnection
|
||||
|
||||
|
||||
@dataclass
|
||||
class Embeds:
|
||||
footer: Footer
|
||||
info: Info
|
||||
announcement: Announcement
|
||||
|
||||
|
||||
@dataclass
|
||||
class Model:
|
||||
channel: Channel
|
||||
embeds: Embeds
|
||||
@@ -0,0 +1,34 @@
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
from src.utils import logger
|
||||
from src.config import config
|
||||
from src.lang.language_models import Model
|
||||
|
||||
class AutoFormatStr(str):
|
||||
def __call__(self):
|
||||
frame = sys._getframe(1)
|
||||
context = {**frame.f_globals, **frame.f_locals}
|
||||
return self.format(**context)
|
||||
|
||||
class LanguageObject:
|
||||
def __init__(self, dictionary: dict):
|
||||
for key, value in dictionary.items():
|
||||
if isinstance(value, dict):
|
||||
setattr(self, key, LanguageObject(value))
|
||||
elif isinstance(value, str):
|
||||
setattr(self, key, AutoFormatStr(value))
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
|
||||
def load_language(lang_code):
|
||||
path = f"src/data/locales/{lang_code}.yaml"
|
||||
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as file:
|
||||
data = yaml.safe_load(file)
|
||||
return LanguageObject(data)
|
||||
except Exception as e:
|
||||
logger(f"Failed loading language file: {e}", "FATAL")
|
||||
|
||||
lang: Model = load_language(config.discord.lang)
|
||||
Reference in New Issue
Block a user