@museumwnf/viewer-core 2.25.2 → 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 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. `lang` and `dir` are set on `<html>`, so a
288
- right-to-left language renders right to left.
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.25.2",
3
+ "version": "2.26.0",
4
4
  "description": "Application engine for MWNF websites: turns a dataset.config.js into a mounted Vue application.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -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
- return (
31
- list.find((candidate) => candidate.toLowerCase() === wanted) ??
32
- list.find((candidate) => candidate.toLowerCase().split('-')[0] === wanted.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'
@@ -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 LEGACY_LANGUAGES[lang] ?? lang
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