From af7f65c29c8a9adeb383984b809786f38e87becf Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Tue, 1 Jul 2025 12:06:08 +0200 Subject: [PATCH] [task-343] [int] --- data/localization/de.json | 17 +++ data/localization/en.json | 17 +++ ivaldi.json | 1 + source/conf.ts | 214 ++++++++++++++++++++++++-------------- source/main.ts | 11 ++ source/types.ts | 11 -- 6 files changed, 181 insertions(+), 90 deletions(-) create mode 100644 data/localization/de.json create mode 100644 data/localization/en.json diff --git a/data/localization/de.json b/data/localization/de.json new file mode 100644 index 0000000..35e5036 --- /dev/null +++ b/data/localization/de.json @@ -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" + } +} diff --git a/data/localization/en.json b/data/localization/en.json new file mode 100644 index 0000000..c8140d3 --- /dev/null +++ b/data/localization/en.json @@ -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" + } +} diff --git a/ivaldi.json b/ivaldi.json index c3c033f..9b52f35 100644 --- a/ivaldi.json +++ b/ivaldi.json @@ -16,6 +16,7 @@ "file", "conf", "log", + "translate", "args" ] } diff --git a/source/conf.ts b/source/conf.ts index fdb581f..c43fb7f 100644 --- a/source/conf.ts +++ b/source/conf.ts @@ -315,11 +315,69 @@ namespace _munin.conf events : string; }; }; - + /** */ - export type type_conf = type_conf_v5; + type type_conf_v6 = { + sources : Array< + ( + { + kind : "ical_feed"; + data : { + url : string; + filtration : { + category_whitelist : (null | Array); + category_blacklist : (null | Array); + title_whitelist : (null | Array); + title_blacklist : (null | Array); + } + } + } + ) + >; + targets : Array< + ( + { + kind : "email"; + data : { + smtp_host : string; + smtp_port : int; + smtp_username : string; + smtp_password : string; + sender : string; + receivers : Array; + hide_tags : boolean; + /** + * in hours + */ + reminders : Array; + } + } + | + { + kind : "telegram_bot"; + data : { + bot_token : string; + chat_id : int; + hide_tags : boolean; + /** + * in hours + */ + reminders : Array; + } + } + ) + >; + 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,27 +992,54 @@ namespace _munin.conf "data": { "nullable": false, "type": "object", - "properties": { - "bot_token": { - "nullable": false, - "type": "string", + "properties": Object.assign( + { + "bot_token": { + "nullable": false, + "type": "string", + }, + "chat_id": { + "nullable": false, + "type": "integer", + }, + "hide_tags": { + "nullable": false, + "type": "boolean", + "default": false, + }, + "reminders": { + "nullable": false, + "type": "array", + "items": schema_reminder(version), + "default": default_reminder(version), + }, }, - "chat_id": { - "nullable": false, - "type": "integer", - }, - "hide_tags": { - "nullable": false, - "type": "boolean", - "default": false, - }, - "reminders": { - "nullable": false, - "type": "array", - "items": schema_reminder(version), - "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); } } diff --git a/source/main.ts b/source/main.ts index af737a4..fd85b7c 100644 --- a/source/main.ts +++ b/source/main.ts @@ -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( diff --git a/source/types.ts b/source/types.ts index 14b2cb6..2174f3c 100644 --- a/source/types.ts +++ b/source/types.ts @@ -30,17 +30,6 @@ namespace _munin monthly = "monthly", } - - /** - */ - export type type_labels = { - head : string; - title : string; - time : string; - location : string; - events : string; - }; - /** */