Compare commits
4 Commits
f4c7b2e18f
...
c7af1fb6ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
c7af1fb6ca
|
|||
|
5226269ec2
|
|||
|
4ac5dd4c88
|
|||
|
8f1cb3fad7
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -17,5 +17,8 @@
|
|||||||
"[json]": {
|
"[json]": {
|
||||||
"editor.defaultFormatter": "denoland.vscode-deno"
|
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||||
},
|
},
|
||||||
|
"[jsonc]": {
|
||||||
|
"editor.defaultFormatter": "denoland.vscode-deno"
|
||||||
|
},
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"exclude": [],
|
"exclude": [],
|
||||||
"imports": {
|
"imports": {
|
||||||
"@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.7"
|
"@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.7",
|
||||||
|
"@std/jsonc": "jsr:@std/jsonc@^1.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
deno.lock
generated
14
deno.lock
generated
@@ -6,6 +6,8 @@
|
|||||||
"jsr:@cliffy/internal@1.0.0-rc.7": "1.0.0-rc.7",
|
"jsr:@cliffy/internal@1.0.0-rc.7": "1.0.0-rc.7",
|
||||||
"jsr:@cliffy/table@1.0.0-rc.7": "1.0.0-rc.7",
|
"jsr:@cliffy/table@1.0.0-rc.7": "1.0.0-rc.7",
|
||||||
"jsr:@std/fmt@~1.0.2": "1.0.7",
|
"jsr:@std/fmt@~1.0.2": "1.0.7",
|
||||||
|
"jsr:@std/json@^1.0.2": "1.0.2",
|
||||||
|
"jsr:@std/jsonc@^1.0.2": "1.0.2",
|
||||||
"jsr:@std/text@~1.0.7": "1.0.13"
|
"jsr:@std/text@~1.0.7": "1.0.13"
|
||||||
},
|
},
|
||||||
"jsr": {
|
"jsr": {
|
||||||
@@ -37,6 +39,15 @@
|
|||||||
"@std/fmt@1.0.7": {
|
"@std/fmt@1.0.7": {
|
||||||
"integrity": "2a727c043d8df62cd0b819b3fb709b64dd622e42c3b1bb817ea7e6cc606360fb"
|
"integrity": "2a727c043d8df62cd0b819b3fb709b64dd622e42c3b1bb817ea7e6cc606360fb"
|
||||||
},
|
},
|
||||||
|
"@std/json@1.0.2": {
|
||||||
|
"integrity": "d9e5497801c15fb679f55a2c01c7794ad7a5dfda4dd1bebab5e409cb5e0d34d4"
|
||||||
|
},
|
||||||
|
"@std/jsonc@1.0.2": {
|
||||||
|
"integrity": "909605dae3af22bd75b1cbda8d64a32cf1fd2cf6efa3f9e224aba6d22c0f44c7",
|
||||||
|
"dependencies": [
|
||||||
|
"jsr:@std/json"
|
||||||
|
]
|
||||||
|
},
|
||||||
"@std/text@1.0.13": {
|
"@std/text@1.0.13": {
|
||||||
"integrity": "2191c90e6e667b0c3b7dea1cd082137580a93b3c136bad597c0212d5fe006eb1"
|
"integrity": "2191c90e6e667b0c3b7dea1cd082137580a93b3c136bad597c0212d5fe006eb1"
|
||||||
}
|
}
|
||||||
@@ -173,7 +184,8 @@
|
|||||||
},
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"jsr:@cliffy/command@1.0.0-rc.7"
|
"jsr:@cliffy/command@1.0.0-rc.7",
|
||||||
|
"jsr:@std/jsonc@^1.0.2"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
// General
|
||||||
"cli_description": "CLI-Tool zum Erzeugen von systemd .timer und .service Units",
|
"cli_description": "CLI-Tool zum Erzeugen von systemd .timer und .service Units",
|
||||||
"cli_create_description": "Erzeugt eine systemd .service und .timer Unit",
|
"cli_create_description": "Erzeugt eine systemd .service und .timer Unit",
|
||||||
|
// Options
|
||||||
"option_name": "Name der Unit-Dateien (optional, wird sonst aus dem Exec generiert)",
|
"option_name": "Name der Unit-Dateien (optional, wird sonst aus dem Exec generiert)",
|
||||||
"option_exec": "Kommando, das durch systemd ausgeführt werden soll",
|
"option_exec": "Kommando, das durch systemd ausgeführt werden soll",
|
||||||
"option_calendar": "OnCalendar-Ausdruck für den Timer",
|
"option_calendar": "OnCalendar-Ausdruck für den Timer",
|
||||||
@@ -14,9 +16,11 @@
|
|||||||
"option_environment": "Environment-Variablen im Format KEY=VALUE",
|
"option_environment": "Environment-Variablen im Format KEY=VALUE",
|
||||||
"option_logfile": "Dateipfad für Log-Ausgabe (stdout/stderr)",
|
"option_logfile": "Dateipfad für Log-Ausgabe (stdout/stderr)",
|
||||||
"option_dry_run": "Gibt die Unit-Dateien nur aus, ohne sie zu schreiben",
|
"option_dry_run": "Gibt die Unit-Dateien nur aus, ohne sie zu schreiben",
|
||||||
|
// Messages
|
||||||
"unit_written_service": "Service Unit geschrieben in: {path}",
|
"unit_written_service": "Service Unit geschrieben in: {path}",
|
||||||
"unit_written_timer": "Timer Unit geschrieben in: {path}",
|
"unit_written_timer": "Timer Unit geschrieben in: {path}",
|
||||||
"hint_header": "\nℹ️ Hinweis:",
|
"hint_header": "\nℹ️ Hinweis:",
|
||||||
|
// Error messages
|
||||||
"error_write_units": "Fehler beim Schreiben der Units:",
|
"error_write_units": "Fehler beim Schreiben der Units:",
|
||||||
"rollback_failed": "Rollback fehlgeschlagen:"
|
"rollback_failed": "Rollback fehlgeschlagen:"
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
// General
|
||||||
"cli_description": "CLI tool for generating systemd .timer and .service units",
|
"cli_description": "CLI tool for generating systemd .timer and .service units",
|
||||||
"cli_create_description": "Generates a systemd .service and .timer unit",
|
"cli_create_description": "Generates a systemd .service and .timer unit",
|
||||||
|
// Options
|
||||||
"option_name": "Name of the unit files (optional, otherwise derived from the exec command)",
|
"option_name": "Name of the unit files (optional, otherwise derived from the exec command)",
|
||||||
"option_exec": "Command to be executed by systemd",
|
"option_exec": "Command to be executed by systemd",
|
||||||
"option_calendar": "OnCalendar expression for the timer",
|
"option_calendar": "OnCalendar expression for the timer",
|
||||||
@@ -14,9 +16,11 @@
|
|||||||
"option_environment": "Environment variables in the format KEY=VALUE",
|
"option_environment": "Environment variables in the format KEY=VALUE",
|
||||||
"option_logfile": "File path for log output (stdout/stderr)",
|
"option_logfile": "File path for log output (stdout/stderr)",
|
||||||
"option_dry_run": "Only outputs the unit files without writing them",
|
"option_dry_run": "Only outputs the unit files without writing them",
|
||||||
|
// Messages
|
||||||
"unit_written_service": "Service unit written to: {path}",
|
"unit_written_service": "Service unit written to: {path}",
|
||||||
"unit_written_timer": "Timer unit written to: {path}",
|
"unit_written_timer": "Timer unit written to: {path}",
|
||||||
"hint_header": "\nℹ️ Note:",
|
"hint_header": "\nℹ️ Note:",
|
||||||
|
// Error messages
|
||||||
"error_write_units": "Error while writing unit files:",
|
"error_write_units": "Error while writing unit files:",
|
||||||
"rollback_failed": "Rollback failed:"
|
"rollback_failed": "Rollback failed:"
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { parse as parseJsonc } from '@std/jsonc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the i18n module by loading
|
* Initializes the i18n module by loading
|
||||||
* the appropriate locale file based on the system language.
|
* the appropriate locale file based on the system language.
|
||||||
@@ -15,29 +17,35 @@ let translations: Record<string, string> = {};
|
|||||||
/**
|
/**
|
||||||
* Loads the translation file for the specified locale.
|
* Loads the translation file for the specified locale.
|
||||||
*
|
*
|
||||||
* Expects a JSON file in the same directory named like `de.json` or `en.json`.
|
* Accepts both `.jsonc` (JSON with comments) and plain `.json`.
|
||||||
|
* When both exist, `.jsonc` takes precedence.
|
||||||
* Falls back to English ('en') if the specified file does not exist.
|
* Falls back to English ('en') if the specified file does not exist.
|
||||||
*
|
*
|
||||||
* @param locale - The language code (e.g., 'de', 'en') to load
|
* @param locale - The language code (e.g., 'de', 'en') to load
|
||||||
* @returns Promise that resolves once the translations have been loaded
|
* @returns Promise that resolves once the translations have been loaded
|
||||||
*/
|
*/
|
||||||
export async function loadLocale(locale: string): Promise<void> {
|
export async function loadLocale(locale: string): Promise<void> {
|
||||||
try {
|
const extensions = ['jsonc', 'json'];
|
||||||
const localeUrl = new URL(`./${locale}.json`, import.meta.url);
|
for (const ext of extensions) {
|
||||||
const file = await Deno.readTextFile(localeUrl);
|
try {
|
||||||
translations = JSON.parse(file);
|
const localeUrl = new URL(`./${locale}.${ext}`, import.meta.url);
|
||||||
} catch (err) {
|
const raw = await Deno.readTextFile(localeUrl);
|
||||||
if (err instanceof Deno.errors.NotFound) {
|
// parseJsonc tolerates both pure JSON and JSONC, so we can use it for either.
|
||||||
console.warn(
|
translations = parseJsonc(raw) as Record<string, string>;
|
||||||
`Locale '${locale}' not found – falling back to 'en'.`,
|
return;
|
||||||
);
|
} catch (err) {
|
||||||
if (locale !== 'en') {
|
if (err instanceof Deno.errors.NotFound) {
|
||||||
await loadLocale('en');
|
// Continue with next extension.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
console.error(`Error parsing locale '${locale}.${ext}':`, err);
|
||||||
console.error('Error loading translation file:', err);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (locale !== 'en') {
|
||||||
|
console.warn(`Locale '${locale}' not found – falling back to 'en'.`);
|
||||||
|
await loadLocale('en');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user