Trans.js 997 B

1234567891011121314151617181920
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var react_1 = require("react");
  7. var useTranslation_1 = __importDefault(require("./useTranslation"));
  8. var formatElements_1 = __importDefault(require("./formatElements"));
  9. function Trans(_a) {
  10. var i18nKey = _a.i18nKey, values = _a.values, components = _a.components, fallback = _a.fallback, defaultTrans = _a.defaultTrans, ns = _a.ns;
  11. var _b = (0, useTranslation_1.default)(ns), t = _b.t, lang = _b.lang;
  12. var result = (0, react_1.useMemo)(function () {
  13. var text = t(i18nKey, values, { fallback: fallback, default: defaultTrans });
  14. if (!components || components.length === 0)
  15. return text;
  16. return (0, formatElements_1.default)(text, components);
  17. }, [i18nKey, values, components, lang]);
  18. return result;
  19. }
  20. exports.default = Trans;