Add UI module translations to Modrinth App (#5489)

* Add UI module translations to Modrinth App

* Replace `await` with `eager: true`

---------

Co-authored-by: Calum H. <calum@modrinth.com>
This commit is contained in:
Jerozgen
2026-03-07 13:13:24 +03:00
committed by GitHub
parent 4b6de7526c
commit d4932d3089
8 changed files with 27 additions and 16 deletions

View File

@@ -94,17 +94,20 @@ const LOCALE_CODES = new Set(LOCALES.map((l) => l.code))
* Usage: buildLocaleMessages(import.meta.glob('./locales/* /index.json', { eager: true }))
*/
export function buildLocaleMessages(
modules: Record<string, { default: CrowdinMessages }>,
...allModules: Record<string, { default: CrowdinMessages }>[]
): Record<string, Record<string, string>> {
const messages: Record<string, Record<string, string>> = {}
for (const [path, module] of Object.entries(modules)) {
// Extract locale code from path like './locales/en-US/index.json' or './src/locales/en-US/index.json'
const match = path.match(/\/([^/]+)\/index\.json$/)
if (match) {
const locale = match[1]
// Only include locales that are in our LOCALES list
if (LOCALE_CODES.has(locale)) {
messages[locale] = transformCrowdinMessages(module.default)
for (const modules of allModules) {
for (const [path, module] of Object.entries(modules)) {
// Extract locale code from path like './locales/en-US/index.json' or './src/locales/en-US/index.json'
const match = path.match(/\/([^/]+)\/index\.json$/)
if (match) {
const locale = match[1]
// Only include locales that are in our LOCALES list
if (LOCALE_CODES.has(locale)) {
const mergedMessages = messages[locale] ?? {}
messages[locale] = Object.assign(mergedMessages, transformCrowdinMessages(module.default))
}
}
}
}

View File

@@ -0,0 +1,6 @@
import type { CrowdinMessages } from './composables/i18n'
export const uiLocaleModulesEager = import.meta.glob<{ default: CrowdinMessages }>(
'./locales/*/index.json',
{ eager: true },
)