You've already forked AstralRinth
forked from didirus/AstralRinth
Add Omorphia locale files loading (#1447)
Implements loading of all locale files shipped with Omorphia package by globbing and registering them during the `vintl:extendOptions` hook. Also updated VIntl for Nuxt to ensure those files are properly loaded. Previous version of VIntl for Nuxt had a somewhat broken module ID tracking, preventing Omorphia locale files to be properly transformed during the build; at least on systems like Windows, don't know about *nix. The tracking approach was replaced in 1.8.0, and it seems to be working now.
This commit is contained in:
@@ -186,7 +186,6 @@ export default defineNuxtConfig({
|
|||||||
|
|
||||||
const resolveCompactNumberDataImport = await (async () => {
|
const resolveCompactNumberDataImport = await (async () => {
|
||||||
const compactNumberLocales: string[] = []
|
const compactNumberLocales: string[] = []
|
||||||
const resolvedImports = new Map<string, string>()
|
|
||||||
|
|
||||||
for await (const localeFile of globIterate(
|
for await (const localeFile of globIterate(
|
||||||
'node_modules/@vintl/compact-number/dist/locale-data/*.mjs',
|
'node_modules/@vintl/compact-number/dist/locale-data/*.mjs',
|
||||||
@@ -194,7 +193,6 @@ export default defineNuxtConfig({
|
|||||||
)) {
|
)) {
|
||||||
const tag = basename(localeFile, '.mjs')
|
const tag = basename(localeFile, '.mjs')
|
||||||
compactNumberLocales.push(tag)
|
compactNumberLocales.push(tag)
|
||||||
resolvedImports.set(tag, String(pathToFileURL(resolve(localeFile))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveImport(tag: string) {
|
function resolveImport(tag: string) {
|
||||||
@@ -207,6 +205,33 @@ export default defineNuxtConfig({
|
|||||||
return resolveImport
|
return resolveImport
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
const resolveOmorphiaLocaleImport = await (async () => {
|
||||||
|
const omorphiaLocales: string[] = []
|
||||||
|
const omorphiaLocaleSets = new Map<string, { files: { from: string }[] }>()
|
||||||
|
|
||||||
|
for await (const localeDir of globIterate('node_modules/omorphia/locales/*', {
|
||||||
|
posix: true,
|
||||||
|
})) {
|
||||||
|
const tag = basename(localeDir)
|
||||||
|
omorphiaLocales.push(tag)
|
||||||
|
|
||||||
|
const localeFiles: { from: string; format?: string }[] = []
|
||||||
|
|
||||||
|
omorphiaLocaleSets.set(tag, { files: localeFiles })
|
||||||
|
|
||||||
|
for await (const localeFile of globIterate(`${localeDir}/*`, { posix: true })) {
|
||||||
|
localeFiles.push({
|
||||||
|
from: pathToFileURL(localeFile).toString(),
|
||||||
|
format: 'default',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return function resolveLocaleImport(tag: string) {
|
||||||
|
return omorphiaLocaleSets.get(matchLocale([tag], omorphiaLocales, 'en-x-placeholder'))
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
for await (const localeDir of globIterate('locales/*/', { posix: true })) {
|
for await (const localeDir of globIterate('locales/*/', { posix: true })) {
|
||||||
const tag = basename(localeDir)
|
const tag = basename(localeDir)
|
||||||
if (isProduction && !enabledLocales.includes(tag) && opts.defaultLocale !== tag) continue
|
if (isProduction && !enabledLocales.includes(tag) && opts.defaultLocale !== tag) continue
|
||||||
@@ -215,20 +240,15 @@ export default defineNuxtConfig({
|
|||||||
opts.locales.find((locale) => locale.tag === tag) ??
|
opts.locales.find((locale) => locale.tag === tag) ??
|
||||||
opts.locales[opts.locales.push({ tag }) - 1]
|
opts.locales[opts.locales.push({ tag }) - 1]
|
||||||
|
|
||||||
|
const localeFiles = (locale.files ??= [])
|
||||||
|
|
||||||
for await (const localeFile of globIterate(`${localeDir}/*`, { posix: true })) {
|
for await (const localeFile of globIterate(`${localeDir}/*`, { posix: true })) {
|
||||||
const fileName = basename(localeFile)
|
const fileName = basename(localeFile)
|
||||||
if (fileName === 'index.json') {
|
if (fileName === 'index.json') {
|
||||||
if (locale.file == null) {
|
localeFiles.push({
|
||||||
locale.file = {
|
from: `./${localeFile}`,
|
||||||
from: `./${localeFile}`,
|
format: 'crowdin',
|
||||||
format: 'crowdin',
|
})
|
||||||
}
|
|
||||||
} else {
|
|
||||||
;(locale.files ??= []).push({
|
|
||||||
from: `./${localeFile}`,
|
|
||||||
format: 'crowdin',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (fileName === 'meta.json') {
|
} else if (fileName === 'meta.json') {
|
||||||
const meta: Record<string, { message: string }> = await fs
|
const meta: Record<string, { message: string }> = await fs
|
||||||
.readFile(localeFile, 'utf8')
|
.readFile(localeFile, 'utf8')
|
||||||
@@ -247,6 +267,11 @@ export default defineNuxtConfig({
|
|||||||
;(locale.meta ??= {}).category = categoryOverride
|
;(locale.meta ??= {}).category = categoryOverride
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const omorphiaLocaleData = resolveOmorphiaLocaleImport(tag)
|
||||||
|
if (omorphiaLocaleData != null) {
|
||||||
|
localeFiles.push(...omorphiaLocaleData.files)
|
||||||
|
}
|
||||||
|
|
||||||
const cnDataImport = resolveCompactNumberDataImport(tag)
|
const cnDataImport = resolveCompactNumberDataImport(tag)
|
||||||
if (cnDataImport != null) {
|
if (cnDataImport != null) {
|
||||||
;(locale.additionalImports ??= []).push({
|
;(locale.additionalImports ??= []).push({
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"@typescript-eslint/parser": "^5.59.8",
|
"@typescript-eslint/parser": "^5.59.8",
|
||||||
"@vintl/compact-number": "^2.0.5",
|
"@vintl/compact-number": "^2.0.5",
|
||||||
"@vintl/how-ago": "^3.0.1",
|
"@vintl/how-ago": "^3.0.1",
|
||||||
"@vintl/nuxt": "^1.7.0",
|
"@vintl/nuxt": "^1.8.0",
|
||||||
"eslint": "^8.41.0",
|
"eslint": "^8.41.0",
|
||||||
"eslint-config-prettier": "^8.8.0",
|
"eslint-config-prettier": "^8.8.0",
|
||||||
"eslint-import-resolver-typescript": "^3.5.5",
|
"eslint-import-resolver-typescript": "^3.5.5",
|
||||||
|
|||||||
637
pnpm-lock.yaml
generated
637
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user