/* eslint-disable no-prototype-builtins */
import { createTranslator, translations as extraTranslations } from '@blocklet/payment-react';
import merge from 'lodash/merge';

import en from './en';
import zh from './zh';

// eslint-disable-next-line import/prefer-default-export
export const translations = merge({ zh, en }, extraTranslations);

export const replace = (template: string, data: Record<string, any> = {}) =>
  template.replace(/{(\w*)}/g, (_, key) => (data.hasOwnProperty(key) ? data[key] : ''));

export const translate = createTranslator({ fallbackLocale: 'en' }, translations);
export const t = translate;
