Trans.js 685 B

1234567891011121314
  1. import { useMemo } from 'react';
  2. import useTranslation from './useTranslation';
  3. import formatElements from './formatElements';
  4. export default function Trans(_a) {
  5. var i18nKey = _a.i18nKey, values = _a.values, components = _a.components, fallback = _a.fallback, defaultTrans = _a.defaultTrans, ns = _a.ns;
  6. var _b = useTranslation(ns), t = _b.t, lang = _b.lang;
  7. var result = useMemo(function () {
  8. var text = t(i18nKey, values, { fallback: fallback, default: defaultTrans });
  9. if (!components || components.length === 0)
  10. return text;
  11. return formatElements(text, components);
  12. }, [i18nKey, values, components, lang]);
  13. return result;
  14. }