Skip to content

Commit ca598e1

Browse files
susnuxbackportbot[bot]
authored andcommitted
chore: add some comments to l10n plugin
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 7583d01 commit ca598e1

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

build/extract-l10n.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,33 @@ extractor.createHtmlParser([
2828
])
2929
.parseFilesGlob('./src/**/*.vue')
3030

31+
const messages = extractor.getMessages()
32+
3133
/**
3234
* remove references to avoid conflicts but save them for code splitting
3335
*
3436
* @type {Record<string,string[]>}
3537
*/
36-
export const context = extractor.getMessages().map((msg) => {
37-
const localContext = [msg.text ?? '', [...new Set(msg.references.map((ref) => ref.split(':')[0] ?? ''))].sort().join(':')]
38+
export const context = messages.map((msg) => {
39+
// mapping of translation ID -> filename(s) [id, filename1:filename2:...]
40+
const idUsage = [
41+
msg.text ?? '',
42+
// get the reference file names only (split off line number), remove duplicates and sort them
43+
[...new Set(msg.references.map((ref) => ref.split(':')[0] ?? ''))].sort().join(':'),
44+
]
45+
// remove reference to avoid conflicts on transifex
3846
msg.references = []
39-
return localContext
40-
}).reduce((p, [id, usage]) => {
41-
const localContext = { ...(Array.isArray(p) ? {} : p) }
47+
return idUsage
48+
}).reduce((localContext, [id, usage]) => {
49+
// add translation bundles to their usage context (filenames -> [ids])
4250
if (usage in localContext) {
4351
localContext[usage].push(id)
4452
return localContext
4553
} else {
4654
localContext[usage] = [id]
4755
}
4856
return localContext
49-
})
57+
}, {})
5058

5159
extractor.savePotFile('./l10n/messages.pot')
5260

build/l10n-plugin.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ export default (dir: string) => {
104104
return `import {t,n,register,${imports.join(',')}} from '\0l10n';register(${imports.join(',')});export {t,n};`
105105
} else if (id === '\0l10n') {
106106
// exports are all chunked translations
107-
const exports = Object.entries(nameMap).map(([usage, id]) => `export const ${id} = ${JSON.stringify(translations[usage])}`).join(';\n')
107+
const exports = Object.entries(nameMap)
108+
.map(([usage, id]) => `export const ${id} = ${JSON.stringify(translations[usage])}`)
109+
.join(';\n')
108110
return `${l10nRegistrationCode}\n${exports}`
109111
}
110112
},

0 commit comments

Comments
 (0)