useTranslation.js 1.0 KB

123456789101112131415161718192021222324
  1. "use strict";
  2. var __assign = (this && this.__assign) || function () {
  3. __assign = Object.assign || function(t) {
  4. for (var s, i = 1, n = arguments.length; i < n; i++) {
  5. s = arguments[i];
  6. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  7. t[p] = s[p];
  8. }
  9. return t;
  10. };
  11. return __assign.apply(this, arguments);
  12. };
  13. var __importDefault = (this && this.__importDefault) || function (mod) {
  14. return (mod && mod.__esModule) ? mod : { "default": mod };
  15. };
  16. Object.defineProperty(exports, "__esModule", { value: true });
  17. var react_1 = require("react");
  18. var wrapTWithDefaultNs_1 = __importDefault(require("./wrapTWithDefaultNs"));
  19. var _context_1 = __importDefault(require("./_context"));
  20. function useTranslation(defaultNS) {
  21. var ctx = (0, react_1.useContext)(_context_1.default);
  22. return (0, react_1.useMemo)(function () { return (__assign(__assign({}, ctx), { t: (0, wrapTWithDefaultNs_1.default)(ctx.t, defaultNS) })); }, [ctx, defaultNS]);
  23. }
  24. exports.default = useTranslation;