UNPKG

macoolka-i18n

Version:

`macoolka-i18n` is a library for internationalization in TypeScript. It easily integrates some localization features to your Application.

280 lines 7.71 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildMonadI18N = exports.extendI18NConfig = exports.getI18NConfig = exports.defaultI18NOption = exports.timeFormatIDs = exports.dateFormatIDs = exports.numberFormatIDs = exports.pluralFormatIDs = exports.relativeFormatIDs = exports.defaultFormats = void 0; var format_1 = require("../format"); var macoolka_object_1 = require("macoolka-object"); var buildI18NFormat_1 = require("./buildI18NFormat"); __exportStar(require("./types"), exports); exports.defaultFormats = { date: { default: { year: 'numeric', month: 'numeric', day: 'numeric' }, shortYear: { year: '2-digit', }, year: { year: 'numeric', }, shortYearMonth: { year: '2-digit', month: '2-digit', }, yearMonth: { year: 'numeric', month: 'numeric', }, shortMonthDay: { month: '2-digit', day: '2-digit', }, monthDay: { month: 'numeric', day: 'numeric', }, shortMonth: { month: '2-digit', }, month: { month: 'numeric', }, shortDay: { day: '2-digit', }, day: { day: 'numeric', }, short: { year: '2-digit', month: '2-digit', day: '2-digit', }, long: { year: 'numeric', month: 'numeric', day: 'numeric', }, full: { year: 'numeric', month: 'numeric', day: 'numeric', weekday: 'long' }, longDateTime: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', }, shortDateTime: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', }, }, time: { default: { hour: 'numeric', minute: 'numeric', }, short: { hour: 'numeric', minute: 'numeric', }, medium: { hour: 'numeric', minute: 'numeric', }, long: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'long' }, full: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'long' }, }, number: { default: { style: 'decimal', minimumFractionDigits: 2, }, int: { style: 'decimal', minimumFractionDigits: 0, }, currency: { style: 'currency', minimumFractionDigits: 2, currency: 'USD' }, precent: { style: 'percent', minimumFractionDigits: 2, }, k: { style: '' } }, relative: { default: { numeric: "auto", unit: 'minute' }, seconds: { style: "narrow", unit: 'seconds', }, minutes: { numeric: "auto", unit: 'minutes' }, hours: { numeric: "auto", unit: 'hours' }, days: { numeric: "auto", unit: 'days' }, weeks: { numeric: "auto", unit: 'weeks' }, months: { numeric: "auto", unit: 'months' }, quarters: { numeric: "auto", unit: 'quarters' }, years: { numeric: "auto", unit: 'years' }, second: { numeric: "auto", unit: 'second' }, minute: { numeric: "auto", unit: 'minute' }, hour: { numeric: "auto", unit: 'hour' }, day: { numeric: "auto", unit: 'day' }, week: { numeric: "auto", unit: 'week' }, month: { numeric: "auto", unit: 'month' }, quarter: { numeric: "auto", unit: 'quarter' }, year: { numeric: "auto", unit: 'year' }, }, plural: { default: { type: 'cardinal', }, cardinal: { type: 'cardinal', }, ordinal: { type: 'ordinal', }, } }; exports.relativeFormatIDs = Object.keys(exports.defaultFormats.relative); exports.pluralFormatIDs = Object.keys(exports.defaultFormats.plural); exports.numberFormatIDs = Object.keys(exports.defaultFormats.number); exports.dateFormatIDs = Object.keys(exports.defaultFormats.date); exports.timeFormatIDs = Object.keys(exports.defaultFormats.time); exports.defaultI18NOption = { template: __assign(__assign({}, exports.defaultFormats), { messages: {} }), templates: { "zh-CN": (0, macoolka_object_1.merge)({}, { number: { default: { style: 'decimal', minimumFractionDigits: 2, }, int: { style: 'decimal', minimumFractionDigits: 0, }, currency: { style: 'currency', minimumFractionDigits: 2, currency: 'CNY' }, precent: { style: 'percent', minimumFractionDigits: 2, }, } }, exports.defaultFormats) }, defaultLocale: 'en', formatters: format_1.standFormat, }; var getI18NConfig = function (a) { return function (b) { if (b === void 0) { b = {}; } return (0, macoolka_object_1.merge)({}, a, b); }; }; exports.getI18NConfig = getI18NConfig; exports.extendI18NConfig = (0, exports.getI18NConfig)(exports.defaultI18NOption); var buildMonadI18N = function (a) { if (a === void 0) { a = { defaultLocale: 'en' }; } return (0, buildI18NFormat_1.buildI18NFormat)((0, exports.extendI18NConfig)(a)); }; exports.buildMonadI18N = buildMonadI18N; //# sourceMappingURL=stand.js.map