UNPKG

tdesign-mobile-vue

Version:
71 lines (67 loc) 1.93 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ import _slicedToArray from '@babel/runtime/helpers/slicedToArray'; import _typeof from '@babel/runtime/helpers/typeof'; import { isString } from 'lodash-es'; function getPluralIndex(count) { if (count === 0) return 0; if (count === 1) return 1; return 2; } function t(pattern) { if (isString(pattern)) { var text = pattern; var count; var data = {}; for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } if (args.length > 0) { var firstArg = args[0], secondArg = args[1]; if (typeof firstArg === "number") { count = firstArg; if (secondArg && _typeof(secondArg) === "object") { data = secondArg; } else { data.count = count; } } else if (_typeof(firstArg) === "object" && firstArg !== null) { data = firstArg; } } if (text.includes("|")) { var pluralParts = text.split("|").map(function (part) { return part.trim(); }); if (typeof count === "number") { var pluralIndex = getPluralIndex(count); if (pluralIndex < pluralParts.length) { text = pluralParts[pluralIndex]; } else { text = pluralParts[pluralParts.length - 1]; } } else { var _pluralParts = _slicedToArray(pluralParts, 1), firstPart = _pluralParts[0]; text = firstPart; } } if (data && Object.keys(data).length > 0) { var regular = /\{\s*([\w-]+)\s*\}/g; text = text.replace(regular, function (match, key) { if (Object.prototype.hasOwnProperty.call(data, key)) { return String(data[key]); } return match; }); } return text; } return ""; } export { t }; //# sourceMappingURL=t.js.map