From 447bafecdc1dea22741ac31ce7754a2ab7586578 Mon Sep 17 00:00:00 2001 From: Jayash Tripathy <76092296+JayashTripathy@users.noreply.github.com> Date: Sun, 14 Sep 2025 11:28:35 +0530 Subject: [PATCH 1/3] fix(i18n): update comments for clarity in constants and manager files --- packages/i18n/scripts/locale/constants.ts | 2 +- packages/i18n/scripts/locale/manager.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/i18n/scripts/locale/constants.ts b/packages/i18n/scripts/locale/constants.ts index a106a69d51..6109195c64 100644 --- a/packages/i18n/scripts/locale/constants.ts +++ b/packages/i18n/scripts/locale/constants.ts @@ -4,7 +4,7 @@ import { TranslationFile, TranslationLocale } from "./types"; /** Root path for all translation files */ export const TRANSLATION_ROOT_PATH = path.join(__dirname, "../../src/locales"); -/** Comma-separated list of translation file categories */ +/** list of translation file categories */ export const TRANSLATION_FILES: TranslationFile[] = ["translations", "accessibility", "editor", "core"]; /** base locale */ diff --git a/packages/i18n/scripts/locale/manager.ts b/packages/i18n/scripts/locale/manager.ts index effe65137c..d0f33e4d40 100644 --- a/packages/i18n/scripts/locale/manager.ts +++ b/packages/i18n/scripts/locale/manager.ts @@ -1,4 +1,3 @@ -// translationManager.ts import { promises as fs } from "fs"; import path from "path"; import { TRANSLATION_ROOT_PATH, TRANSLATION_FILES, BASE_LOCALE } from "./constants"; From 39ad110ca003da3fea7837057fce44cfb89d1c58 Mon Sep 17 00:00:00 2001 From: Jayash Tripathy <76092296+JayashTripathy@users.noreply.github.com> Date: Sun, 14 Sep 2025 12:08:38 +0530 Subject: [PATCH 2/3] refactor(i18n): lint --- packages/i18n/scripts/locale/file-service.ts | 1 - packages/i18n/scripts/locale/json-service.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/i18n/scripts/locale/file-service.ts b/packages/i18n/scripts/locale/file-service.ts index 8542be9d2b..ae0d4c2fb0 100644 --- a/packages/i18n/scripts/locale/file-service.ts +++ b/packages/i18n/scripts/locale/file-service.ts @@ -1,4 +1,3 @@ -// fileService.ts import { promises as fs } from "fs"; export class FileService { diff --git a/packages/i18n/scripts/locale/json-service.ts b/packages/i18n/scripts/locale/json-service.ts index 784742abb8..a8603fc69b 100644 --- a/packages/i18n/scripts/locale/json-service.ts +++ b/packages/i18n/scripts/locale/json-service.ts @@ -1,4 +1,3 @@ -// jsonService.ts import _ from "lodash"; export interface NestedTranslations { From b3c36ca8e08f9dc3f07f69c906100407c1d45333 Mon Sep 17 00:00:00 2001 From: Jayash Tripathy <76092296+JayashTripathy@users.noreply.github.com> Date: Mon, 15 Sep 2025 00:37:27 +0530 Subject: [PATCH 3/3] refactor(i18n): add method to update all generated translations and refactor flattening logic in JsonService --- .../scripts/check-missing-translations.ts | 2 ++ packages/i18n/scripts/locale/json-service.ts | 26 +++++++++---------- packages/i18n/scripts/locale/manager.ts | 10 ++++++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/i18n/scripts/check-missing-translations.ts b/packages/i18n/scripts/check-missing-translations.ts index ebdd9aad63..76a83801b0 100644 --- a/packages/i18n/scripts/check-missing-translations.ts +++ b/packages/i18n/scripts/check-missing-translations.ts @@ -8,6 +8,8 @@ import { TranslationRow, TranslationStatus } from "./locale/types"; async function checkMissingTranslations() { try { const manager = new LocaleManager(); + await manager.updateAllGeneratedTranslations(); + const files = manager.translationFiles; let hasMissingTranslations = false; diff --git a/packages/i18n/scripts/locale/json-service.ts b/packages/i18n/scripts/locale/json-service.ts index a8603fc69b..4eee30a0c8 100644 --- a/packages/i18n/scripts/locale/json-service.ts +++ b/packages/i18n/scripts/locale/json-service.ts @@ -12,19 +12,19 @@ export class JsonService { * @returns A flattened object with dot-notation keys */ flatten(obj: NestedTranslations, prefix = ""): Record { - return Object.keys(obj).reduce( - (acc, key) => { - const newKey = prefix ? `${prefix}.${key}` : key; - if (_.isPlainObject(obj[key])) { - Object.assign(acc, this.flatten(obj[key] as NestedTranslations, newKey)); - } else { - // Handle empty strings explicitly - acc[newKey] = obj[key] === "" ? "" : (obj[key] as string); - } - return acc; - }, - {} as Record - ); + const result: Record = {}; + + for (const [key, value] of Object.entries(obj)) { + const newKey = prefix ? `${prefix}.${key}` : key; + + if (typeof value === "object" && value !== null) { + Object.assign(result, this.flatten(value as NestedTranslations, newKey)); + } else { + result[newKey] = value === "" ? "" : (value as string); + } + } + + return result; } /** diff --git a/packages/i18n/scripts/locale/manager.ts b/packages/i18n/scripts/locale/manager.ts index d0f33e4d40..e4ab8a86e2 100644 --- a/packages/i18n/scripts/locale/manager.ts +++ b/packages/i18n/scripts/locale/manager.ts @@ -29,7 +29,6 @@ export class LocaleManager { constructor() { this.rootPath = TRANSLATION_ROOT_PATH; this.translationFiles = TRANSLATION_FILES; - this.translationFiles.forEach((f) => this.updateGeneratedTranslations(f)); } /** @@ -42,6 +41,15 @@ export class LocaleManager { return files.filter((f) => isValidLocaleDirectory(f)) as TranslationLocale[]; } + /** + * Update all the generated translation files in the memory + */ + async updateAllGeneratedTranslations(): Promise { + for (const file of this.translationFiles) { + await this.updateGeneratedTranslations(file); + } + } + /** * Constructs the full file path for a translation file * @param locale The locale identifier (e.g., 'en', 'fr')