@museumwnf/viewer-core 2.13.0 → 2.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@museumwnf/viewer-core",
3
- "version": "2.13.0",
3
+ "version": "2.14.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",
package/src/i18n/index.js CHANGED
@@ -47,18 +47,23 @@ export function mergeMessages(...catalogues) {
47
47
  export function createI18n({ messages = {}, locale = BASE_LANGUAGE } = {}) {
48
48
  const current = ref(locale)
49
49
 
50
- const t = (key) => {
51
- const active = messages[current.value]
50
+ // A text in a language of the caller's choosing (a record's own, say),
51
+ // English where that language has none.
52
+ const tIn = (language, key) => {
53
+ const active = messages[language]
52
54
  if (active && typeof active[key] === 'string') return active[key]
53
55
  const base = messages[BASE_LANGUAGE]
54
56
  if (base && typeof base[key] === 'string') return base[key]
55
57
  return key
56
58
  }
57
59
 
60
+ const t = (key) => tIn(current.value, key)
61
+
58
62
  const i18n = {
59
63
  locale: current,
60
64
  availableLocales: Object.keys(messages),
61
65
  t,
66
+ tIn,
62
67
  install(app) {
63
68
  app.provide(VIEWER_I18N, i18n)
64
69
  // `$t` in a template, `useI18n()` in a script — the two shapes Vue