UNPKG

@qite/tide-booking-component

Version:

React Booking wizard & Booking product component for Tide

56 lines (48 loc) 1.42 kB
import { fr, nlBE } from "date-fns/locale"; export const languages = ["nl-BE", "fr-BE"]; export const defaultLanguage = "nl-BE"; export const formatPrice = (price: number, locale: string = "nl-BE") => { const priceFormat = Intl.NumberFormat(locale, { style: "currency", currency: "EUR", minimumFractionDigits: 2, useGrouping: true, }); return priceFormat.format(price); }; import frJson from "../translations/fr-BE.json"; import nlJson from "../translations/nl-BE.json"; export const getTranslations = (language: string) => { switch (language) { case "nl-BE": return nlJson; case "fr-BE": return frJson; default: throw new Error(`The language '${language}' is not yet supported.`); } }; export const locales = { "nl-BE": nlBE, "fr-BE": fr, }; export function getLocale(code: string) { switch (code) { case "nl-BE": return locales[code]; case "fr-BE": return locales[code]; default: return locales["nl-BE"]; } } export const getPriceDifferenceText = (price: number) => { return price > 0 ? `+ ${formatPrice(Math.abs(price))}` : `- ${formatPrice(Math.abs(price))}`; }; export function format(text: string, args: any[]) { return text.replace(/{([0-9]+)}/g, function (match, index) { return typeof args[index] == "undefined" ? match : args[index]; }); }