@rockpack/localazer
Version:
This module can help you organize localization in your React application
35 lines (34 loc) • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sprintf = exports.nl = exports.l = exports.i18n = void 0;
var jed_1 = __importDefault(require("jed"));
var react_1 = require("react");
var server_1 = require("react-dom/server");
exports.i18n = new jed_1.default({ domain: 'messages' });
var l = function (text, context) { return function () { return (context ?
exports.i18n.pgettext(context, text) :
exports.i18n.gettext(text)); }; };
exports.l = l;
var nl = function (singular, plural, amount, context) { return function () { return (context ?
exports.i18n.npgettext(context, singular, plural, amount) :
exports.i18n.ngettext(singular, plural, amount)); }; };
exports.nl = nl;
var sprintf = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return function () { return (exports.i18n.sprintf.apply(exports.i18n, args.map(function (item) {
if (react_1.isValidElement(item)) {
return server_1.renderToStaticMarkup(item);
}
else if (typeof item === 'function') {
return item();
}
return item;
}))); };
};
exports.sprintf = sprintf;