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:
+11
-7
@@ -3,9 +3,12 @@ import random
|
||||
|
||||
from src.utils import get_operator_metadata, get_next_station, format_via_list, format_stop_list
|
||||
from src.dc.helpers import format_timestamp_to_dc
|
||||
from src.lang.locales import lang
|
||||
|
||||
lang_embed = lang.embeds
|
||||
|
||||
def build_embed_footer(mode: str, slogans):
|
||||
footer_notice = f"Data provided by https://transitous.org • mode: {mode}"
|
||||
footer_notice = f"{lang.embeds.footer.notice()} • mode: {mode}"
|
||||
icon = "https://raw.githubusercontent.com/kaaninchen/Gleiswechsel/refs/heads/main/src/data/assets/transitous-logo.png"
|
||||
|
||||
if slogans is not None:
|
||||
@@ -22,14 +25,15 @@ def build_embed_footer(mode: str, slogans):
|
||||
def build_info_embed() -> discord.Embed:
|
||||
from src.dc.handlers import trip
|
||||
|
||||
station = trip["station"]
|
||||
agency = trip["agency"]
|
||||
metadata = get_operator_metadata(agency, trip["route_color"], trip["mode"])
|
||||
departure = format_timestamp_to_dc(trip["departure"])
|
||||
arrival = format_timestamp_to_dc(trip["arrival"])
|
||||
|
||||
|
||||
embed = discord.Embed(
|
||||
title = trip["long_name"],
|
||||
description=f"Abfahrt von {trip["station"]} um {departure}. Ankunft um {arrival}",
|
||||
description=lang_embed.info.description(),
|
||||
color = metadata["color"]
|
||||
)
|
||||
|
||||
@@ -40,12 +44,12 @@ def build_info_embed() -> discord.Embed:
|
||||
if next_stop:
|
||||
next_stop_station = next_stop.get("name")
|
||||
|
||||
via = format_via_list(stops)
|
||||
via = format_via_list(stops, lang_embed.info.via_and())
|
||||
|
||||
if via:
|
||||
embed.add_field(name="Über", value=via, inline=False)
|
||||
embed.add_field(name=lang_embed.info.via(), value=via, inline=False)
|
||||
if next_stop:
|
||||
embed.add_field(name="Nächster Halt", value=f"__{next_stop_station}__", inline=False)
|
||||
embed.add_field(name=lang_embed.info.next_stop(), value=f"__{next_stop_station}__", inline=False)
|
||||
|
||||
route_fields = format_stop_list(stops, next_stop_station)
|
||||
for field_name, field_value in route_fields:
|
||||
@@ -65,7 +69,7 @@ def build_announcement_embed(msg):
|
||||
metadata = get_operator_metadata(agency, trip["route_color"], trip["mode"])
|
||||
|
||||
embed = discord.Embed(
|
||||
title = "Informationen zu ihrer Fahrt",
|
||||
title = lang_embed.announcement.title(),
|
||||
description=msg,
|
||||
color=metadata["color"]
|
||||
)
|
||||
|
||||
+6
-5
@@ -1,12 +1,14 @@
|
||||
import discord
|
||||
import asyncio
|
||||
import random
|
||||
from datetime import datetime, timedelta, date
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from src.utils import logger, channel_formatting, choose_connection, get_sound_path, LOCAL_TZ, get_next_station
|
||||
from src.config import config
|
||||
from src.lang.locales import lang
|
||||
|
||||
_scheduled_task: asyncio.Task | None = None
|
||||
channel_lang = lang.channel
|
||||
|
||||
async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = False):
|
||||
global trip, _scheduled_task
|
||||
@@ -35,7 +37,7 @@ async def rename_vc(bot: discord.Bot, voice_channel, from_scheduler: bool = Fals
|
||||
|
||||
formatting = channel_formatting(mode)
|
||||
await voice_channel.edit(name=f"{formatting}{long_name}")
|
||||
await voice_channel.set_status(f"Ankunft um {arrival}")
|
||||
await voice_channel.set_status(channel_lang.status())
|
||||
|
||||
logger(f"Updated channel name!")
|
||||
|
||||
@@ -56,8 +58,7 @@ async def announcer(announcement: str, voice_channel: discord.VoiceChannel, dest
|
||||
announcement_status = await voice_announcer(destination, voice_channel)
|
||||
if announcement_status:
|
||||
return
|
||||
embed = build_announcement_embed(
|
||||
f'Sehr geehrte Fahrgäste,\nIn wenigen Minuten erreichen wir {destination}. Dieser Zug endet dort.\n\nWir wünschen Ihnen eine angenehme Weiterreise.\n\nVielen Dank für ihr Vertrauen und auf Wiedersehen.')
|
||||
embed = build_announcement_embed(lang.embeds.announcement.end_of_connection.message())
|
||||
case "transfer":
|
||||
embed = build_info_embed()
|
||||
case _:
|
||||
@@ -96,7 +97,7 @@ async def _schedule_next_transfer(bot: discord.Bot, arrival_dt: datetime, voice_
|
||||
|
||||
if wait_seconds > 0:
|
||||
remaining = str(timedelta(seconds=wait_seconds))
|
||||
logger(f"Nexxt transfer in {remaining.split('.')[0]} ({arrival_dt.strftime('%H:%M')} Uhr)")
|
||||
logger(f"Next transfer in {remaining.split('.')[0]} ({arrival_dt.strftime('%H:%M')} Uhr)")
|
||||
|
||||
if wait_seconds > announcement_countdown:
|
||||
wait_until_end_announcement = wait_seconds - announcement_countdown
|
||||
|
||||
Reference in New Issue
Block a user