@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
89 lines (87 loc) • 3.71 kB
JavaScript
try {
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "8508461a-79b6-47ae-aeed-9854fe3c4b1d", e._sentryDebugIdIdentifier = "sentry-dbid-8508461a-79b6-47ae-aeed-9854fe3c4b1d");
} catch (e) {}
import { t as en_US_default } from "./en-US-cJAmQhFR.js";
//#region src/language/config.ts
/**
* FALLBACK_LOCALE - **MUST** match the locale string in the above import
*/
var FALLBACK_LOCALE = "en-US";
var defaultTranslation = en_US_default;
//#endregion
//#region src/language/utils.ts
/**
* Convert to ISO 639-1
*/
var toTwoLetterCode = (locale) => locale.toLowerCase().substring(0, 2);
/**
* Matches a string with one of the locales
* @example
* matchLocale('en-GB');
* // 'en-US'
*/
var matchLocale = (locale, supportedLocales) => supportedLocales.find((supLoc) => toTwoLetterCode(supLoc) === toTwoLetterCode(locale)) ?? null;
/**
* Returns a locale with the proper format
*
* @example
* formatLocale('En_us');
* // 'en-US'
*/
function formatLocale(localeParam) {
const locale = localeParam.replace("_", "-");
if (/([a-z]{2})(-)([A-Z]{2})/.test(locale)) return locale;
const [languageCode, countryCode] = locale.split("-");
if (!languageCode || !countryCode) return null;
const fullLocale = [languageCode.toLowerCase(), countryCode.toUpperCase()].join("-");
return fullLocale.length === 5 ? fullLocale : null;
}
/**
* Checks the locale format.
* Also checks if it's on the locales array.
* If it is not, tries to match it with one.
*/
function parseLocale(locale, supportedLocales = []) {
if (!locale || locale.length < 1 || locale.length > 5) return FALLBACK_LOCALE;
const formattedLocale = formatLocale(locale);
if (Boolean(formattedLocale && supportedLocales.includes(formattedLocale))) return formattedLocale;
return matchLocale(formattedLocale || locale, supportedLocales);
}
var replaceTranslationValues = (translation, values) => translation.replace(/%{(\w+)}/g, (_, k) => values?.[k]?.toString() ?? "");
/**
* Returns a translation string by key
*/
var getTranslationByKey = (translations, key, options = { values: {} }) => {
const localizedKey = `${key}${options.localizeFor ? `__${options.localizeFor}` : ""}`;
if (localizedKey in translations) return replaceTranslationValues(translations[localizedKey], options.values);
if (key in translations) return replaceTranslationValues(translations[key], options.values);
return null;
};
/**
* Returns a LanguageCode from locale
* @param locale - The locale the user wants to use
*
* @example for getLanguageCode('en-US')
* // returns 'en'
*/
var getLanguageCode = (locale) => {
const [languageCode] = locale.split("-");
return languageCode;
};
var isTranslationObject = (value) => value !== null && typeof value === "object" && "key" in value && "values" in value;
/**
* A helper function to translate a `Translatable` type, which can be either a simple string key
* or an object with a key and values for interpolation. It uses the provided `i18next` `t` function.
*
* @param t - The `i18next` translation function.
* @param translatable - The string or object to translate.
* @returns The translated string.
*/
var translateTranslatable = (t, translatable) => {
if (!translatable) return void 0;
if (isTranslationObject(translatable)) return t(($) => $[translatable.key], translatable.values);
return t(($) => $[translatable]);
};
//#endregion
export { translateTranslatable as a, parseLocale as i, getLanguageCode as n, FALLBACK_LOCALE as o, getTranslationByKey as r, defaultTranslation as s, formatLocale as t };