@museumwnf/viewer-core 2.25.1 → 2.26.0
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/README.md +5 -3
- package/package.json +1 -1
- package/src/catalogue/catalogueResults.js +14 -1
- package/src/dxa/gallery/useGalleryCollection.js +1 -1
- package/src/i18n/language.js +14 -4
- package/src/index.js +1 -1
- package/src/legacySites.js +2 -2
package/README.md
CHANGED
|
@@ -233,7 +233,7 @@ normally reaches for that instead of calling `mergeMessages` itself.
|
|
|
233
233
|
| `<I18nText keypath tag="div">` | a text rendered as Markdown (block) |
|
|
234
234
|
| `<I18nTextInline keypath tag="span">` | the same, without the surrounding paragraph |
|
|
235
235
|
| `mergeMessages(...catalogues)` | the merge rule above |
|
|
236
|
-
| `negotiateLanguage`, `isRtl` | the language rules, for a website that needs them directly |
|
|
236
|
+
| `negotiateLanguage`, `isRtl`, `LEGACY_LANGUAGE_CODES` | the language rules, for a website that needs them directly |
|
|
237
237
|
| `renderBlock(text, { breaks, glossary })`, `renderInline(text, { breaks, glossary })`, `renderPlain(text)` | the Markdown pipeline `I18nText`/`I18nTextInline` render through, for a website that needs it directly (a data-package field, not a text) |
|
|
238
238
|
| `md(text, { glossary, breaks = true })`, `mdInline(text, { glossary })`, `mdStrip(text)` | the same three, under the record-field convention: `''` for a missing text, line breaks kept by default (a text in the dictionary is prose; a record's field is typed with breaks on purpose) |
|
|
239
239
|
|
|
@@ -284,8 +284,10 @@ visitor's remembered choice, then their browser's preferences, then English —
|
|
|
284
284
|
skipping at every step anything the website does not offer. On a website
|
|
285
285
|
offering more than one language the URL carries `?lang=`, so a page can be
|
|
286
286
|
linked and shared in the language it was read in; a single-language website
|
|
287
|
-
never gets the parameter. `
|
|
288
|
-
|
|
287
|
+
never gets the parameter. Legacy MWNF's own codes `se`, `ch` and `si`
|
|
288
|
+
(`LEGACY_LANGUAGE_CODES`) select `sv`, `zh` and `sl` on a website that offers
|
|
289
|
+
the ISO code, so an old link keeps its language. `lang` and `dir` are set on
|
|
290
|
+
`<html>`, so a right-to-left language renders right to left.
|
|
289
291
|
|
|
290
292
|
### Which languages a website offers
|
|
291
293
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, toValue } from 'vue'
|
|
1
|
+
import { computed, toValue, watchEffect } from 'vue'
|
|
2
2
|
import { useDataPackage } from '../composables/useDataPackage.js'
|
|
3
3
|
import { entityRef } from '../composables/useEntities.js'
|
|
4
4
|
import { useI18n } from '../i18n/index.js'
|
|
@@ -42,6 +42,19 @@ export function useCatalogueResults(spec, { entity: routeEntity = '' } = {}) {
|
|
|
42
42
|
]
|
|
43
43
|
const { filters, page, active, apply, reset, goToPage } = useListQuery({ keys })
|
|
44
44
|
|
|
45
|
+
// A URL value in an older spelling (a legacy country code) is turned into
|
|
46
|
+
// the facet's own as soon as the facet can read it, so the controls bound
|
|
47
|
+
// to `filters`, the options they match and the summary all see the value
|
|
48
|
+
// the records carry. Re-runs when the route writes the old spelling back.
|
|
49
|
+
watchEffect(() => {
|
|
50
|
+
for (const [key, facet] of Object.entries(current.value.facets ?? {})) {
|
|
51
|
+
const value = filters[key]
|
|
52
|
+
if (!facet.canonical || !value) continue
|
|
53
|
+
const wanted = facet.canonical(value)
|
|
54
|
+
if (wanted != null && String(wanted) !== value) filters[key] = String(wanted)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
45
58
|
const helpers = {
|
|
46
59
|
t,
|
|
47
60
|
locale,
|
|
@@ -156,7 +156,7 @@ export function useGalleryCollection(data, config = {}) {
|
|
|
156
156
|
/** The filter summary line legacy printed as "Collection | <selections>". */
|
|
157
157
|
function filterSummary(filters, t) {
|
|
158
158
|
const parts = []
|
|
159
|
-
if (filters.country) parts.push(labelOf('countries', countryIdForCode(filters.country)))
|
|
159
|
+
if (filters.country) parts.push(labelOf('countries', countryIdForCode(FACETS.country.canonical(filters.country) ?? filters.country)))
|
|
160
160
|
for (const key of FACET_CATEGORIES) if (filters[key]) parts.push(tagLabelForLegacy(filters[key]))
|
|
161
161
|
if (filters.from) parts.push(`${t('catalogue.filter.from')} ${filters.from}`)
|
|
162
162
|
if (filters.to) parts.push(`${t('catalogue.filter.to')} ${filters.to}`)
|
package/src/i18n/language.js
CHANGED
|
@@ -17,20 +17,30 @@ export function isRtl(code) {
|
|
|
17
17
|
return RTL_LANGUAGES.has(String(code ?? '').toLowerCase().split('-')[0])
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Legacy MWNF's own codes where they differ from ISO 639-1: Swedish, Chinese
|
|
22
|
+
* and Slovenian. The sites offer the ISO code; an old address (`?lang=se`) or
|
|
23
|
+
* a choice remembered before the switch still selects the language.
|
|
24
|
+
*/
|
|
25
|
+
export const LEGACY_LANGUAGE_CODES = Object.freeze({ se: 'sv', ch: 'zh', si: 'sl' })
|
|
26
|
+
|
|
20
27
|
/**
|
|
21
28
|
* The URL first, then the visitor's own earlier choice, then what their
|
|
22
29
|
* browser asks for, then English. A language that is not offered is ignored at
|
|
23
30
|
* every step, so nothing here can select a language the website does not have.
|
|
31
|
+
* A legacy code (LEGACY_LANGUAGE_CODES) matches its ISO language when the
|
|
32
|
+
* website does not offer the legacy code itself.
|
|
24
33
|
*/
|
|
25
34
|
export function negotiateLanguage(offered, { requested, stored, preferred = [] } = {}) {
|
|
26
35
|
const list = offered?.length ? offered : ['en']
|
|
27
36
|
const match = (code) => {
|
|
28
37
|
if (!code) return undefined
|
|
29
38
|
const wanted = String(code).toLowerCase()
|
|
30
|
-
|
|
31
|
-
list.find((candidate) => candidate.toLowerCase() ===
|
|
32
|
-
list.find((candidate) => candidate.toLowerCase().split('-')[0] ===
|
|
33
|
-
)
|
|
39
|
+
const found = (code) =>
|
|
40
|
+
list.find((candidate) => candidate.toLowerCase() === code) ??
|
|
41
|
+
list.find((candidate) => candidate.toLowerCase().split('-')[0] === code.split('-')[0])
|
|
42
|
+
const iso = LEGACY_LANGUAGE_CODES[wanted.split('-')[0]]
|
|
43
|
+
return found(wanted) ?? (iso ? found(iso) : undefined)
|
|
34
44
|
}
|
|
35
45
|
return (
|
|
36
46
|
match(requested) ??
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export { useDataPackage } from './composables/useDataPackage.js'
|
|
|
13
13
|
export { byId, entityRef, loadEntities, useEntities } from './composables/useEntities.js'
|
|
14
14
|
export { resolveRecordLanguage, useRecordLanguage } from './composables/useRecordLanguage.js'
|
|
15
15
|
export { createI18n, mergeMessages, useI18n, useLocale } from './i18n/index.js'
|
|
16
|
-
export { isRtl, negotiateLanguage } from './i18n/language.js'
|
|
16
|
+
export { LEGACY_LANGUAGE_CODES, isRtl, negotiateLanguage } from './i18n/language.js'
|
|
17
17
|
export { md, mdInline, mdStrip, renderBlock, renderInline, renderPlain } from './i18n/markdown.js'
|
|
18
18
|
export { languageLabels, offeredLanguages } from './languages.js'
|
|
19
19
|
export { defaultScrollBehavior, resolveViews } from './router/index.js'
|
package/src/legacySites.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { legacyRecordId } from './legacyIds.js'
|
|
2
2
|
import { siblingSiteUrl } from './rights.js'
|
|
3
|
+
import { LEGACY_LANGUAGE_CODES } from './i18n/language.js'
|
|
3
4
|
|
|
4
5
|
// Links to legacy MWNF sites that have a new one (inventory-app#2482). The
|
|
5
6
|
// legacy sites linked to each other by address, and those addresses are in
|
|
@@ -171,11 +172,10 @@ function publicationsRoute(path, url) {
|
|
|
171
172
|
// A legacy address writes its language as legacy MWNF wrote it; the sites
|
|
172
173
|
// offer it as ISO 639-1. The two differ only for Swedish, Chinese and
|
|
173
174
|
// Slovenian; the other legacy codes are ISO already.
|
|
174
|
-
const LEGACY_LANGUAGES = { se: 'sv', ch: 'zh', si: 'sl' }
|
|
175
175
|
function isoLanguage(code) {
|
|
176
176
|
if (!/^[a-z]{2}$/i.test(code ?? '')) return null
|
|
177
177
|
const lang = code.toLowerCase()
|
|
178
|
-
return
|
|
178
|
+
return LEGACY_LANGUAGE_CODES[lang] ?? lang
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// Legacy travels.museumwnf.org's Exhibition Trails: a country's or a theme's
|