-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathlunaria.config.ts
More file actions
88 lines (81 loc) · 2.81 KB
/
lunaria.config.ts
File metadata and controls
88 lines (81 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { defineConfig } from '@lunariajs/core/config'
import type { Locale, Merge } from '@lunariajs/core'
import { currentLocales, countryLocaleVariants } from './config/i18n.ts'
// The source locale is `en` (en.json contains all reference translation keys).
// Country variants like `en-US` inherit from `en` via the merge config.
const sourceLocale: Locale = { label: 'English', lang: 'en' }
// Build the list of Lunaria locales from currentLocales.
// currentLocales has expanded codes (en-US, en-GB, ar-EG, es-ES, es-419, etc.)
// but NOT the base codes (ar, es) that the variants inherit from.
// We need to add those base codes as Lunaria locales too, so they can be
// referenced in the merge config and tracked independently.
const localeSet = new Set<string>()
const locales: Locale[] = []
for (const l of currentLocales) {
if (l.code === sourceLocale.lang || !l.name) continue
if (!localeSet.has(l.code)) {
localeSet.add(l.code)
locales.push({ label: l.name, lang: l.code })
}
}
// Add base language codes (ar, es, etc.) that aren't already in the list.
// These are the keys of countryLocaleVariants that aren't the source locale.
for (const baseLang of Object.keys(countryLocaleVariants)) {
if (baseLang === sourceLocale.lang) continue
if (!localeSet.has(baseLang)) {
// Use the first variant's name or the base code as label
const variants = countryLocaleVariants[baseLang]!
const label = variants[0]?.name ?? baseLang
localeSet.add(baseLang)
locales.push({ label, lang: baseLang })
}
}
if (locales.length === 0) {
throw new Error('No locales found besides source locale')
}
// Build merge config from countryLocaleVariants:
// Each variant locale merges keys from its base locale, so keys present in
// the base file count as covered for the variant.
// e.g. { 'en-US': ['en'], 'en-GB': ['en'], 'ar-EG': ['ar'], 'es-ES': ['es'], 'es-419': ['es'] }
const merge: Merge = {}
for (const [baseLang, variants] of Object.entries(countryLocaleVariants)) {
for (const variant of variants) {
// Each variant merges from its base language and (if not the source) implicitly
// from the source via normal Lunaria tracking.
const existing = merge[variant.code]
if (existing) {
existing.push(baseLang)
} else {
merge[variant.code] = [baseLang]
}
}
}
export default defineConfig({
repository: {
name: 'npmx-dev/npmx.dev',
},
sourceLocale,
locales: locales as [Locale, ...Locale[]],
files: [
{
include: ['i18n/locales/en.json'],
pattern: 'i18n/locales/@lang.json',
type: 'dictionary',
merge,
optionalKeys: {
$schema: true,
vacations: true,
},
},
],
tracking: {
ignoredKeywords: [
'lunaria-ignore',
'typo',
'en-only',
'broken link',
'i18nReady',
'i18nIgnore',
],
},
})