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