UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

69 lines (68 loc) 2.27 kB
import { FALLBACK_LOCALE as p, DEFAULT_TRANSLATIONS as C } from "./constants/localization.js"; import { hasOwnProperty as f } from "../../utils/struct/property.js"; import { EMPTY_OBJECT as u } from "../../utils/value/constants.js"; import { asPlainObject as O } from "../../utils/struct/main.js"; import { isFunction as d } from "../../utils/value/is.js"; const g = { values: u, count: 0 }, w = /^[a-z]{2}-[A-Z]{2}$/, l = (e) => e.substring(0, 2).toLowerCase(); function E(e, t) { if (!e) return null; const r = l(e); return t.find((n) => l(n) === r) || null; } function _(e) { const t = e.replace("_", "-"); if (w.test(t)) return t; const [r, n] = t.split("-"); if (!r || !n) return null; const o = `${r.toLowerCase()}-${n.toUpperCase()}`; return o.length === 5 ? o : null; } function m(e, t) { const r = e.trim(); if (!r || r.length < 1 || r.length > 5) return p; const n = _(r); return n && t.includes(n) ? n : E(n ?? r, t); } function S(e = u, t) { return e === u ? e : Object.keys(e).reduce((r, n) => { const o = _(n) || m(n, t); return o && e[n] && (r[o] = e[n]), r; }, {}); } const L = (e, t) => { if (d(t)) { const r = /* @__PURE__ */ new Map(); let n = -1; return e.replace(/%{(\w+)}/g, (o, c) => { let i = r.get(c) ?? -1; const A = t(c, ++n, ++i) ?? ""; return r.set(c, i), A; }); } return e.replace(/%{(\w+)}/g, (r, n) => (t == null ? void 0 : t[n]) ?? ""); }, b = (e, t, r = g) => { const n = r.count ?? 0, o = `${t}__${n}`; if (f(e, o) && e[o]) return L(e[o], r.values); const c = `${t}__plural`; return f(e, c) && n > 1 && e[c] ? L(e[c], r.values) : f(e, t) && e[t] ? L(e[t], r.values) : null; }, h = async (e, t = u, r = u) => { const n = m(e, Object.keys(t)) || p, o = t[n]; return { ...C, // Default en-US translations (in case any other translation file is missing any key) ...await (d(o) ? o() : o) ?? u, // Merge with our locale file of the locale they are loading ...O(r == null ? void 0 : r[e]) // Merge with their custom locales if available }; }; export { S as formatCustomTranslations, _ as formatLocale, b as getTranslation, h as loadTranslations, E as matchLocale, m as parseLocale, l as toTwoLetterCode };