UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 1.97 kB
import{getTranslation as t,formatCustomTranslations as s,parseLocale as e}from"./utils.js";import{getLocalisedAmount as i}from"../utils/amount-util.js";import{CDN_SUPPORTED_LOCALES as o,DEFAULT_LOCALE as a}from"./constants.js";import r from"../packages/server/translations/en-US.json.js";function n(t,s,e){return s in t?Object.defineProperty(t,s,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[s]=e,t}class l{async requestTranslations(){const t=await this.service.fetchTranslationsFromCdn(this.locale);this._translations={...r,...t,...Boolean(this.customTranslations[this.locale])&&this.customTranslations[this.locale]}}get translations(){return this._translations}get(s,e){const i=t(this._translations,s,e);return null!==i?i:s}amount(t,s,e){return i(t,this.locale,s,e)}date(t,s={}){if(void 0===t)return"";const e={year:"numeric",month:"2-digit",day:"2-digit",...s};return new Date(t).toLocaleDateString(this.locale,e)}dateTime(t){return void 0===t?"":this.timeAndDateFormatter.format(new Date(t))}createSupportedLocalesList(t){if(!t)return o;const s=new Set([...o,...Object.keys(t)]);return Array.from(s).sort((t,s)=>t.localeCompare(s))}constructor(t){n(this,"locale",void 0),n(this,"languageCode",void 0),n(this,"service",void 0),n(this,"customTranslations",void 0),n(this,"supportedLocales",void 0),n(this,"_translations",{}),n(this,"timeFormatOptions",{hour:"numeric",minute:"numeric"}),n(this,"timeAndDateFormatOptions",{year:"numeric",month:"2-digit",day:"2-digit",...this.timeFormatOptions}),n(this,"timeAndDateFormatter",void 0);const{locale:i,customTranslations:o,service:r}=t;this.service=r,this.customTranslations=s(o),this.supportedLocales=this.createSupportedLocalesList(this.customTranslations),this.locale=e(i||a,this.supportedLocales),this.languageCode=this.locale.split("-")[0],this.timeAndDateFormatter=Intl.DateTimeFormat(this.locale,this.timeAndDateFormatOptions)}}export{l as Language,l as default}; //# sourceMappingURL=Language.js.map