@revolugo/common 7.11.1-alpha.44 → 7.11.1-alpha.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolugo/common",
|
|
3
|
-
"version": "7.11.1-alpha.
|
|
3
|
+
"version": "7.11.1-alpha.45",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Revolugo common",
|
|
6
6
|
"author": "Revolugo",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"./constants": "./src/constants/index.ts",
|
|
16
16
|
"./currencies": "./src/currencies/index.ts",
|
|
17
17
|
"./http": "./src/http/index.ts",
|
|
18
|
+
"./i18n": "./src/i18n/index.ts",
|
|
18
19
|
"./icons": "./src/icons/index.ts",
|
|
19
20
|
"./map": "./src/map/index.ts",
|
|
20
21
|
"./models": "./src/models/index.ts",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { LANG_TO_LOCALE, LOCALES, Lang } from '../constants/locales.ts'
|
|
2
|
+
|
|
3
|
+
/** Matches `@nuxtjs/i18n` `LocaleObject<string>` (index signature required for Nuxt config assignability). */
|
|
4
|
+
export interface NuxtI18nLocaleConfig {
|
|
5
|
+
[key: string]: unknown
|
|
6
|
+
code: string
|
|
7
|
+
files?: string[]
|
|
8
|
+
language: string
|
|
9
|
+
name: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Options for {@link nuxtI18nLocales}. */
|
|
13
|
+
export interface NuxtI18nLocalesOptions {
|
|
14
|
+
/** App-specific messages in `i18n/locales/{code}.json`. */
|
|
15
|
+
appLocaleFiles?: boolean
|
|
16
|
+
languages?: Lang[]
|
|
17
|
+
/**
|
|
18
|
+
* Also register BCP47 locale codes (`en-US`, `fr-FR`, …) as route prefixes,
|
|
19
|
+
* before each lang code (`en`, `fr`, …), for legacy URLs.
|
|
20
|
+
*/
|
|
21
|
+
regionalLocales?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function nuxtI18nLocales(
|
|
25
|
+
options: NuxtI18nLocalesOptions = {},
|
|
26
|
+
): NuxtI18nLocaleConfig[] {
|
|
27
|
+
const {
|
|
28
|
+
appLocaleFiles = false,
|
|
29
|
+
languages = Object.values(Lang),
|
|
30
|
+
regionalLocales = false,
|
|
31
|
+
} = options
|
|
32
|
+
|
|
33
|
+
const langLocales = languages.map(lang => {
|
|
34
|
+
const meta = Object.values(LOCALES).find(entry => entry.locale === lang)
|
|
35
|
+
if (!meta) {
|
|
36
|
+
throw new Error(`No locale metadata for language "${lang}"`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const files: string[] = []
|
|
40
|
+
if (appLocaleFiles) {
|
|
41
|
+
files.push(`${lang}.json`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
code: lang as string,
|
|
46
|
+
...(files.length > 0 ? { files } : {}),
|
|
47
|
+
language: LANG_TO_LOCALE[lang] as string,
|
|
48
|
+
name: meta.name,
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
if (!regionalLocales) {
|
|
53
|
+
return langLocales
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return langLocales.flatMap(langLocale => {
|
|
57
|
+
const lang = langLocale.code as Lang
|
|
58
|
+
const regionalCode = LANG_TO_LOCALE[lang] as string
|
|
59
|
+
|
|
60
|
+
return [
|
|
61
|
+
{
|
|
62
|
+
code: regionalCode,
|
|
63
|
+
...(langLocale.files ? { files: [...langLocale.files] } : {}),
|
|
64
|
+
language: regionalCode,
|
|
65
|
+
name: LOCALES[LANG_TO_LOCALE[lang]].name,
|
|
66
|
+
},
|
|
67
|
+
langLocale,
|
|
68
|
+
]
|
|
69
|
+
})
|
|
70
|
+
}
|