Localisation was the lowest dimension on the board at 12. The repo already had
the vue-i18n layer — 11 locales, one JSON per area, eager glob, fallbackLocale
en — so this adds an AREA, not a mechanism: library/i18n/locales/<lc>/
regions.json, 51 keys x 8 locales, every string COPIED from their own
common.json rather than translated by me. The composer takes the namespace from
the FILENAME, so the files are flat like legend.json (a "regions" wrapper would
have produced regions.regions.*).
★ THE REASON IT DIDN'T WORK, AND WHY IT FAILED SILENTLY. With the Spanish
catalogue provably in the bundle, every string still rendered English. The
bundle installed i18n with app.use() but never app.provide('appI18n') — so
ProfileLoader could not drive the locale (it does exactly that at
ProfileLoader.vue:168-169, from profile-config.locale, its "established
contract"), and createAppI18n resolves its locale ONCE from <html lang>, which
every generated leaf page bakes as "en". One line, copied from
doxa-simple-map/index.js:84-86. It degraded quietly because the t() shim falls
back to its key, so a missing catalogue renders as English instead of throwing —
convenient in production, and exactly what hid this.
t() is a shim, not vue-i18n's t(), because their keys ARE English sentences and
several contain dots ('Loading results...', 'Type to search...') which is
vue-i18n's key separator. tm() returns the namespace object and we index it by
the literal string, so the port reads 1:1 with their source: t('Prayer
Coverage'). Plugin-local, per the placement rule — it is four lines shaped
entirely by how these pages were written.
THE DATA FOLLOWS THE LOCALE TOO, which the chrome alone would have hidden. The
prayer API localises its labels from ?lang=, and our components read
cfg.languageCode while the locale arrives as cfg.locale. Measured with ar: the
whole UI translated and every country in the table stayed English. Now the fetch
falls through locale/lang and refetches on change (Angola -> the Arabic list).
RTL: ar sets dir on OUR OWN root via RTL_LOCALES, the house pattern
(doxa-simple-map.vue:246/1346) — never document.documentElement, which belongs
to whatever page embeds us. Verified in a screenshot, not just an attribute: the
goal cards reverse order, the table right-aligns, the progress bars fill from
the right.
A CLONE FIX came free with it. Porting their uupgListTranslations.ts — the
authoritative list of what this component's labels are called — corrected
strings I had written from the markup instead: the rop1 filter is "People Group"
and I had "Affinity Bloc"; the search placeholder is the full "Search names,
country/continent, religions..."; prayer_coverage reads "Intercessors".
Two assertions of mine were wrong again, both failing on correct behaviour: the
back-link compared for equality when it carries their leading arrow, and the RTL
check read document.documentElement.dir when an embedded element must not set it.
Not done: it/ro/zh have no regions.json — DX-life translates 8 of our 11 — and
resolve through fallbackLocale en, which library/i18n/README says is fine.
Oswald (their Cyrillic heading face) is still unvendored.
English unchanged throughout: region 68/68 vs live, country 28/28, chooser, map
and dashboard suites all green, no gate newly red.
70 lines
3.3 KiB
JavaScript
70 lines
3.3 KiB
JavaScript
/**
|
|
* plugin-designs/regions-dashboard/index.js
|
|
*
|
|
* Bundle entry — registers the regions-dashboard web component.
|
|
*
|
|
* This bundle ships the Driver's 2-tab Regions element as three flat profiles:
|
|
* regions-list.vue — tab 1, "Regions List"
|
|
* region-dashboards.vue — tab 2, "Region Dashboards"
|
|
* regions-mfe.vue — the COMPOSITE that carries the SELECT VIEW switcher over both
|
|
* tabs and forwards tab 1's selection to tab 2
|
|
*
|
|
* The composite nests the two tabs as <regions-dashboard> custom elements of this SAME bundle,
|
|
* each with its own `profile` — so one download serves all three, exactly as my-upg-100-list's
|
|
* upg-100-mfe does. That is why the glob below must keep matching every flat .vue here.
|
|
*
|
|
* Usage from a host page:
|
|
* <script src="/doxa-maps/regions-dashboard/regions-dashboard.js"></script>
|
|
* <regions-dashboard profile-config='{"profile":"regions-mfe"}'></regions-dashboard>
|
|
*
|
|
* `profile` must match a flat .vue filename in this folder (without the .vue).
|
|
* The profile-config attribute is parsed by ProfileLoader (in @map).
|
|
*/
|
|
|
|
import { defineCustomElement } from 'vue'
|
|
import { createPinia } from 'pinia'
|
|
import ProfileLoader from '@map/ProfileLoader.vue'
|
|
import { createAppI18n } from '@map/i18n/index.js'
|
|
|
|
// ─── Bundle-private profile registry ─────────────────────────────────────────
|
|
// import.meta.glob is evaluated by Vite at build time relative to THIS file, so it
|
|
// captures only this bundle's profiles — flat .vue files sitting directly here, no
|
|
// profiles/ subfolder. Handed to ProfileLoader via app.provide('profileModules', ...).
|
|
const profileModules = import.meta.glob('./*.vue')
|
|
|
|
/**
|
|
* Build the defineCustomElement-wrapped class for this bundle.
|
|
* Each instance gets its own Pinia + i18n — isolation that matters if multiple
|
|
* <regions-dashboard> embeds ever share one page.
|
|
*/
|
|
function buildRegionsDashboardElement() {
|
|
return defineCustomElement(ProfileLoader, {
|
|
configureApp(app) {
|
|
app.use(createPinia())
|
|
// Install i18n AND hand the instance to ProfileLoader by reference, the way
|
|
// doxa-simple-map/index.js:84-86 does. app.use() alone is not enough: createAppI18n()
|
|
// resolves its locale ONCE from <html lang>, and every generated leaf page bakes
|
|
// lang="en", so the element was permanently English no matter what the host asked for.
|
|
// ProfileLoader drives appI18n.global.locale.value from profile-config.locale (its
|
|
// "established contract", ProfileLoader.vue:148-169) — but only if appI18n is PROVIDED.
|
|
// MEASURED before this line: with a Spanish catalogue present in the bundle and es set,
|
|
// every string still rendered English, and silently, because the t() shim falls back to
|
|
// its key rather than throwing.
|
|
const i18n = createAppI18n()
|
|
app.use(i18n)
|
|
app.provide('appI18n', i18n)
|
|
app.provide('profileModules', profileModules)
|
|
}
|
|
})
|
|
}
|
|
|
|
const RegionsDashboardElement = buildRegionsDashboardElement()
|
|
|
|
// Guard prevents "already registered" errors when this IIFE is loaded twice.
|
|
if (typeof customElements !== 'undefined') {
|
|
if (!customElements.get('regions-dashboard')) {
|
|
customElements.define('regions-dashboard', RegionsDashboardElement)
|
|
}
|
|
}
|
|
|
|
export default RegionsDashboardElement
|