Zeichenketten auslagern #2

Merged
fenris merged 2 commits from task-343 into main 2025-07-01 19:05:52 +02:00
6 changed files with 181 additions and 90 deletions
Showing only changes of commit af7f65c29c - Show all commits

17
data/localization/de.json Normal file
View file

@ -0,0 +1,17 @@
{
"meta": {
"identifier": "de",
"name": "Deutsch"
},
"tree": {
"event": "Termin",
"events": "Termine",
"reminder": "Erinnerung",
"title_long": "Titel",
"title_short": "was",
"time_long": "Datum und Uhrzeit",
"time_short": "wann",
"location_long": "Ort",
"location_short": "wo"
}
}

17
data/localization/en.json Normal file
View file

@ -0,0 +1,17 @@
{
"meta": {
"identifier": "en",
"name": "English"
},
"tree": {
"event": "event",
"events": "events",
"reminder": "reminder",
"title_long": "title",
"title_short": "what",
"time_long": "date and time",
"time_short": "when",
"location_long": "location",
"location_short": "where"
}
}

View file

@ -16,6 +16,7 @@
"file",
"conf",
"log",
"translate",
"args"
]
}

View file

@ -319,7 +319,65 @@ namespace _munin.conf
/**
*/
export type type_conf = type_conf_v5;
type type_conf_v6 = {
sources : Array<
(
{
kind : "ical_feed";
data : {
url : string;
filtration : {
category_whitelist : (null | Array<string>);
category_blacklist : (null | Array<string>);
title_whitelist : (null | Array<string>);
title_blacklist : (null | Array<string>);
}
}
}
)
>;
targets : Array<
(
{
kind : "email";
data : {
smtp_host : string;
smtp_port : int;
smtp_username : string;
smtp_password : string;
sender : string;
receivers : Array<string>;
hide_tags : boolean;
/**
* in hours
*/
reminders : Array<type_reminder_raw>;
}
}
|
{
kind : "telegram_bot";
data : {
bot_token : string;
chat_id : int;
hide_tags : boolean;
/**
* in hours
*/
reminders : Array<type_reminder_raw>;
}
}
)
>;
settings : {
interval : float;
};
};
/**
*/
export type type_conf = type_conf_v6;
/**
@ -538,6 +596,25 @@ namespace _munin.conf
}
/**
*/
function convert_from_v5(
conf_v5 : type_conf_v5
) : type_conf_v6
{
lib_plankton.log._notice(
"munin.conf.dropping_labels",
{
}
);
return {
"source": conf_v5.sources,
"targets": conf_v5.targets,
"settings": conf_v5.settings,
};
}
/**
*/
function schema_source_kalender_digital(
@ -695,7 +772,8 @@ namespace _munin.conf
) : lib_plankton.conf.type_schema
{
switch (version) {
case "1": {
case "1":
{
return {
"nullable": false,
"type": "array",
@ -709,7 +787,8 @@ namespace _munin.conf
break;
}
default:
case "2": {
case "2":
{
return {
"nullable": false,
"type": "array",
@ -743,7 +822,6 @@ namespace _munin.conf
"type": "integer",
};
}
case "5":
default:
{
return {
@ -802,7 +880,6 @@ namespace _munin.conf
{
return [24];
}
case "5":
default:
{
return [
@ -915,7 +992,8 @@ namespace _munin.conf
"data": {
"nullable": false,
"type": "object",
"properties": {
"properties": Object.assign(
{
"bot_token": {
"nullable": false,
"type": "string",
@ -936,6 +1014,32 @@ namespace _munin.conf
"default": default_reminder(version),
},
},
(() => {
switch (version)
{
case "1":
case "2":
case "3":
case "4":
case "5":
{
return {};
break;
}
default:
{
return {
"language": {
"nullable": false,
"type": "string",
"default": "de"
},
};
break;
}
}
}) ()
),
"additionalProperties": false,
"required": [
"bot_token",
@ -973,8 +1077,6 @@ namespace _munin.conf
];
break;
}
case "4":
case "5":
default:
{
return [
@ -1015,54 +1117,10 @@ namespace _munin.conf
}
/**
*/
function schema_labels(
version : string
) : lib_plankton.conf.type_schema
{
return {
"nullable": false,
"type": "object",
"properties": {
"head": {
"nullable": false,
"type": "string",
"default": "Termin-Erinnerung"
},
"title": {
"nullable": false,
"type": "string",
"default": "was"
},
"time": {
"nullable": false,
"type": "string",
"default": "wann"
},
"location": {
"nullable": false,
"type": "string",
"default": "wo"
},
"events": {
"nullable": false,
"type": "string",
"default": "Termine"
},
},
"additionalProperties": false,
"required": [
],
"default": {}
};
}
/**
*/
export function schema(
version : string = "5"
version : string = "6"
) : lib_plankton.conf.type_schema
{
switch (version) {
@ -1088,10 +1146,7 @@ namespace _munin.conf
};
break;
}
case "2":
case "3":
case "4":
case "5":
default:
{
return {
"nullable": false,
@ -1128,7 +1183,8 @@ namespace _munin.conf
"2": {"target": "3", "function": convert_from_v2},
"3": {"target": "4", "function": convert_from_v3},
"4": {"target": "5", "function": convert_from_v4},
"5": null,
"5": {"target": "6", "function": convert_from_v5},
"6": null,
}
);
@ -1166,7 +1222,7 @@ namespace _munin.conf
}
}
*/
return (conf_raw.content as type_conf_v5);
return (conf_raw.content as type_conf_v6);
}
}

View file

@ -108,6 +108,17 @@ namespace _munin
args_raw.join(" ")
);
await lib_plankton.translate.initialize(
{
"packages": [
lib_plankton.json.decode(
await lib_plankton.file.read("localization/de.json"),
await lib_plankton.file.read("localization/en.json"),
),
],
}
);
if (args.help) {
process.stdout.write(
arg_handler.generate_help(

View file

@ -31,17 +31,6 @@ namespace _munin
}
/**
*/
export type type_labels = {
head : string;
title : string;
time : string;
location : string;
events : string;
};
/**
*/
export type type_event = {