From cc375801c2cc9c7462fcd5b1991599979bf7a0c3 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 19 Feb 2024 20:33:19 +0100 Subject: [PATCH] #756 - Faster translation checks --- src/commands/i18n.ts | 22 ++++++++++++++++++++-- src/services/PagesParser.ts | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/commands/i18n.ts b/src/commands/i18n.ts index 7de89362..ad6a106b 100644 --- a/src/commands/i18n.ts +++ b/src/commands/i18n.ts @@ -24,6 +24,8 @@ import { LocalizationKey } from '../localization'; // Support for DeepL, Azure export class i18n { + private static processedFiles: { [filePath: string]: { dir: string; filename: string; isPageBundle: boolean; }} = {}; + /** * Registers the i18n commands. */ @@ -31,6 +33,15 @@ export class i18n { const subscriptions = Extension.getInstance().subscriptions; subscriptions.push(commands.registerCommand(COMMAND_NAME.i18n.create, i18n.create)); + + i18n.clearFiles(); + } + + /** + * Clear the processed files + */ + public static clearFiles() { + i18n.processedFiles = {}; } /** @@ -315,6 +326,10 @@ export class i18n { * @returns An object containing the filename and directory. */ private static async getFileInfo(filePath: string): Promise<{ filename: string; dir: string }> { + if (i18n.processedFiles[filePath]) { + return i18n.processedFiles[filePath]; + } + const fileInfo = parse(filePath); let filename = fileInfo.base; let dir = fileInfo.dir; @@ -329,10 +344,13 @@ export class i18n { dir += '/'; } - return { + i18n.processedFiles[filePath] = { + isPageBundle, filename, dir - }; + } + + return i18n.processedFiles[filePath]; } /** diff --git a/src/services/PagesParser.ts b/src/services/PagesParser.ts index f573ebff..d3195d2d 100644 --- a/src/services/PagesParser.ts +++ b/src/services/PagesParser.ts @@ -77,6 +77,7 @@ export class PagesParser { * Parse all pages in the workspace */ public static async parsePages() { + i18n.clearFiles(); const ext = Extension.getInstance(); // Update the dashboard with the fresh data