From 1103c6840ecd0074f69dcf2ac759a168b7117ae7 Mon Sep 17 00:00:00 2001 From: David Czihak Date: Fri, 8 May 2026 19:28:05 +0200 Subject: Refactor: Rename localizedText to localizeText --- Scripts/main.js | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'Scripts/main.js') diff --git a/Scripts/main.js b/Scripts/main.js index a98dfef..bde902c 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -191,7 +191,7 @@ function buildZigArgv(config, options) { function safeCleanPaths(cwd) { const showWarning = () => { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.clean.unsafe_cwd", "Refusing to clean: the working directory must be inside this workspace." ) @@ -379,7 +379,14 @@ function activeZigFileDirectory() { return nova.path.dirname(filePath); } -function localizedText(key, fallback, variables) { +/** + * Resolve a localized string, substituting `{variable}` placeholders + * + * @param {string} key - Key + * @param {string} fallback - Fallback text + * @param {*} variables - Dictionary of variable names and values + */ +function localizeText(key, fallback, variables) { let text = nova.localize(key, fallback); if (!variables || typeof variables !== "object") { @@ -444,7 +451,7 @@ async function resolveZigExecutable() { const zigPath = await resolveExecutable(CONFIG_KEYS.zigPath, "zig"); if (!zigPath) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.zig.not_found", "Zig was not found. Install it or set a Zig executable path in Zig extension settings.", ), @@ -573,7 +580,7 @@ function registerCommands() { if (!command) { workspace.showWarningMessage( - localizedText( + localizeText( "warning.terminal.launch_failed", "Unable to launch the Zig task in Terminal." ) @@ -583,7 +590,7 @@ function registerCommands() { const result = await launchInTerminal(buildShellCommand(command, args, cwd)); if (result.status !== 0) { - const prefix = localizedText( + const prefix = localizeText( "warning.terminal.open_failed", "Unable to open Terminal for the Zig task." ); @@ -680,7 +687,7 @@ class ZigLanguageServer { if (!zlsPath) { this.warnMissingTool( "zls", - localizedText( + localizeText( "warning.zls.not_found", "ZLS was not found. Install it or set a ZLS executable path in Zig extension settings." ) @@ -712,7 +719,7 @@ class ZigLanguageServer { const client = new LanguageClient( LANGUAGE_CLIENT_ID, - localizedText("name.language_server", "Zig Language Server"), + localizeText("name.language_server", "Zig Language Server"), serverOptions, clientOptions ); @@ -736,7 +743,7 @@ class ZigLanguageServer { if (error) { console.error(`[${LANGUAGE_CLIENT_ID}] ${error.message}`); nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.zls.stopped_unexpectedly", "The Zig language server stopped unexpectedly ({executable}).", { executable: zlsPath || "zls" }, @@ -757,7 +764,7 @@ class ZigLanguageServer { } catch (error) { console.error(`[${LANGUAGE_CLIENT_ID}] Failed to start ZLS`, error); nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.zls.start_failed", "Unable to start the Zig language server at {path}.", { path: zlsPath } @@ -822,7 +829,7 @@ class ZigTaskAssistant { constructor() { this.disposable = nova.assistants.registerTaskAssistant(this, { identifier: TASK_ASSISTANT_ID, - name: localizedText("name.extension", "Zig"), + name: localizeText("name.extension", "Zig"), }); } @@ -836,7 +843,7 @@ class ZigTaskAssistant { provideTasks() { const tasks = []; - const currentFile = new Task(localizedText("task.current_file.name", "Current Zig File")); + const currentFile = new Task(localizeText("task.current_file.name", "Current Zig File")); currentFile.setAction(Task.Run, new TaskResolvableAction({ data: { type: "current-file-run", @@ -855,7 +862,7 @@ class ZigTaskAssistant { if (steps && steps.length > 0) { for (const step of steps) { const task = new Task( - localizedText("task.build_step.name", "Zig Build: {step}", { step }) + localizeText("task.build_step.name", "Zig Build: {step}", { step }) ); task.setAction(Task.Run, new TaskResolvableAction({ data: { @@ -919,7 +926,7 @@ class ZigTaskAssistant { async resolveCleanAction(cwd) { if (!cwd) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.clean.missing_cwd", "Choose a workspace or working directory before cleaning Zig build artifacts." ) @@ -1055,7 +1062,7 @@ class ZigTaskAssistant { const cwd = filePath ? nova.path.dirname(filePath) : null; if (!filePath || !cwd) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.current_file.focus_editor_for_run", "Focus a Zig editor before running Current Zig File." ) @@ -1070,7 +1077,7 @@ class ZigTaskAssistant { const startDir = activeZigFileDirectory(); if (!startDir) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.current_file.focus_editor_for_clean", "Focus a Zig editor before cleaning Current Zig File artifacts." ) @@ -1087,7 +1094,7 @@ class ZigTaskAssistant { (); if (!lldbDapPath) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.lldb_dap.not_found", "lldb-dap was not found. Install Xcode Command Line Tools or set an LLDB DAP executable path in Zig extension settings." ) @@ -1108,7 +1115,7 @@ class ZigTaskAssistant { } if (!programPath) { nova.workspace.showWarningMessage( - localizedText( + localizeText( "warning.debug.choose_program", "Choose a program path before running Zig Debug." ) -- cgit v1.3