@datagouv/components-next 1.0.2-dev.189 → 1.0.2-dev.190
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/dist/{Datafair.client-Bb3KFfHG.js → Datafair.client-VsEj9A00.js} +1 -1
- package/dist/{ImagePreview.client-dU0DyxhO.js → ImagePreview.client-cv32--L0.js} +1 -1
- package/dist/{JsonPreview.client-oCcmf4Sj.js → JsonPreview.client-JmyzznjY.js} +2 -2
- package/dist/{MapContainer.client-o50vZ4p7.js → MapContainer.client-BxGjbFJV.js} +2 -2
- package/dist/{PdfPreview.client-DXYcyV9H.js → PdfPreview.client-CkrjnmJP.js} +2 -2
- package/dist/{Pmtiles.client-D1eRUmQj.js → Pmtiles.client-EAekMgpr.js} +1 -1
- package/dist/{PreviewWrapper.vue_vue_type_script_setup_true_lang-A3Ige7AN.js → PreviewWrapper.vue_vue_type_script_setup_true_lang-B0OeAb39.js} +1 -1
- package/dist/{XmlPreview.client-DpaqaBjv.js → XmlPreview.client-WcOMRUAD.js} +3 -3
- package/dist/components-next.js +1 -1
- package/dist/{index-C6RfMwqg.js → index-DLsJxwiN.js} +1 -1
- package/dist/{leaflet-src-CezuL8aR.js → leaflet-src-D0FPslrZ.js} +1 -1
- package/dist/{main-DseJBKsd.js → main-HzoTSLAM.js} +5419 -5412
- package/dist/{vue3-xml-viewer.common-GEec9TSv.js → vue3-xml-viewer.common-iq0K0tIG.js} +1 -1
- package/package.json +1 -1
- package/src/composables/useTranslation.ts +24 -9
package/package.json
CHANGED
|
@@ -14,24 +14,39 @@ const translationModules = import.meta.glob<Record<string, string>>('../../../lo
|
|
|
14
14
|
import: 'default',
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
+
const LANGUAGE_SUBTAG_REGEX = /^[a-z]{2,3}$/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extract the language subtag of an `accept-language` header or of
|
|
21
|
+
* `navigator.language`, and return it only if it is a well-formed one.
|
|
22
|
+
*
|
|
23
|
+
* Both are user-controlled, and the locale is handed over to `Intl` formatters,
|
|
24
|
+
* which throw a `RangeError` on anything that is not a valid language tag. The
|
|
25
|
+
* wildcard `*` is rejected here too: it means "any language", so it must fall
|
|
26
|
+
* back to the next detection step.
|
|
27
|
+
*/
|
|
28
|
+
function parseLanguage(value: string | undefined | null): string | null {
|
|
29
|
+
if (!value) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
const language = value.split(';')[0]!.split(',')[0]!.split('-')[0]!.toLowerCase()
|
|
33
|
+
return LANGUAGE_SUBTAG_REGEX.test(language) ? language : null
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
function detectLanguage(): string {
|
|
18
37
|
// Server-side (Nuxt)
|
|
19
38
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
if (acceptLanguage) {
|
|
23
|
-
const primaryLang = acceptLanguage.split(';')[0]!.split(',')[0]!.split('-')[0]!.toLowerCase()
|
|
24
|
-
// Ignore wildcard * language, that should fallback to client side detection or default language
|
|
25
|
-
if (primaryLang !== '*') return primaryLang
|
|
26
|
-
}
|
|
39
|
+
const language = parseLanguage(useRequestHeader?.('accept-language'))
|
|
40
|
+
if (language) return language
|
|
27
41
|
}
|
|
28
42
|
catch {
|
|
29
43
|
// useRequestHeaders not available, continue to client-side detection
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
// Client-side
|
|
33
|
-
if (typeof window !== 'undefined'
|
|
34
|
-
|
|
47
|
+
if (typeof window !== 'undefined') {
|
|
48
|
+
const language = parseLanguage(navigator.language)
|
|
49
|
+
if (language) return language
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
return 'fr'
|