From ce0abf33bb799cd2859692d6da8b7a8a15fe42cb Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 23 Dec 2025 16:08:16 +0100 Subject: [PATCH 1/2] build: fix translations in vue modules When a vue file is handled by vite it will have some query string like `source.vue?lang=ts&...` so to properly add the correct translations for that file we need to remove the query string. This resolves an issue where some files (e.g. `NcAppSettingsShortcutsSection`) were missing their translations in the bundle. Signed-off-by: Ferdinand Thiessen --- build/l10n-plugin.mts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build/l10n-plugin.mts b/build/l10n-plugin.mts index 67d03575e3..774bf194a7 100644 --- a/build/l10n-plugin.mts +++ b/build/l10n-plugin.mts @@ -48,9 +48,7 @@ export default (dir: string) => { for (const locale in allTranslations) { const currentTranslations = allTranslations[locale]! for (const [usage, msgIds] of Object.entries(context)) { - if (!(usage in translations)) { - translations[usage] = [] - } + translations[usage] ??= [] // split the translations by usage in components translations[usage]!.push({ l: locale, @@ -78,8 +76,9 @@ export default (dir: string) => { return null } else if (source.endsWith('l10n.ts') && importer && !importer.includes('node_modules')) { if (dirname(resolve(dirname(importer), source)).split('/').at(-1) === 'src') { + const [path] = importer.split('?', 2) // return our wrapper for handling the import - return `\0l10nwrapper?source=${encodeURIComponent(importer)}` + return `\0l10nwrapper?source=${encodeURIComponent(path!)}` } } }, From 6d48a9a6d325bc60df45458ee6a648000707720a Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 23 Dec 2025 16:08:46 +0100 Subject: [PATCH 2/2] chore: add some comments to l10n plugin Signed-off-by: Ferdinand Thiessen --- build/extract-l10n.mjs | 20 ++++++++++++++------ build/l10n-plugin.mts | 4 +++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build/extract-l10n.mjs b/build/extract-l10n.mjs index 31084673a3..acb943ff68 100644 --- a/build/extract-l10n.mjs +++ b/build/extract-l10n.mjs @@ -28,17 +28,25 @@ extractor.createHtmlParser([ ]) .parseFilesGlob('./src/**/*.vue') +const messages = extractor.getMessages() + /** * remove references to avoid conflicts but save them for code splitting * * @type {Record} */ -export const context = extractor.getMessages().map((msg) => { - const localContext = [msg.text ?? '', [...new Set(msg.references.map((ref) => ref.split(':')[0] ?? ''))].sort().join(':')] +export const context = messages.map((msg) => { + // mapping of translation ID -> filename(s) [id, filename1:filename2:...] + const idUsage = [ + msg.text ?? '', + // get the reference file names only (split off line number), remove duplicates and sort them + [...new Set(msg.references.map((ref) => ref.split(':')[0] ?? ''))].sort().join(':'), + ] + // remove reference to avoid conflicts on transifex msg.references = [] - return localContext -}).reduce((p, [id, usage]) => { - const localContext = { ...(Array.isArray(p) ? {} : p) } + return idUsage +}).reduce((localContext, [id, usage]) => { + // add translation bundles to their usage context (filenames -> [ids]) if (usage in localContext) { localContext[usage].push(id) return localContext @@ -46,7 +54,7 @@ export const context = extractor.getMessages().map((msg) => { localContext[usage] = [id] } return localContext -}) +}, {}) extractor.savePotFile('./l10n/messages.pot') diff --git a/build/l10n-plugin.mts b/build/l10n-plugin.mts index 774bf194a7..a85ef607dc 100644 --- a/build/l10n-plugin.mts +++ b/build/l10n-plugin.mts @@ -104,7 +104,9 @@ export default (dir: string) => { return `import {t,n,register,${imports.join(',')}} from '\0l10n';register(${imports.join(',')});export {t,n};` } else if (id === '\0l10n') { // exports are all chunked translations - const exports = Object.entries(nameMap).map(([usage, id]) => `export const ${id} = ${JSON.stringify(translations[usage])}`).join(';\n') + const exports = Object.entries(nameMap) + .map(([usage, id]) => `export const ${id} = ${JSON.stringify(translations[usage])}`) + .join(';\n') return `${l10nRegistrationCode}\n${exports}` } },