UNPKG

react-intl

Version:

Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.

53 lines (52 loc) 2.26 kB
"use strict"; /* * Copyright 2015, Yahoo Inc. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = __importStar(require("react")); var injectIntl_1 = __importDefault(require("./injectIntl")); var FormattedPlural = function (props) { var value = props.value, other = props.other, children = props.children, _a = props.intl, formatPlural = _a.formatPlural, Text = _a.textComponent; var pluralCategory = formatPlural(value, props); var formattedPlural = props[pluralCategory] || other; if (typeof children === 'function') { return children(formattedPlural); } if (Text) { return React.createElement(Text, null, formattedPlural); } // Work around @types/react where React.FC cannot return string return formattedPlural; }; FormattedPlural.defaultProps = { type: 'cardinal', }; FormattedPlural.displayName = 'FormattedPlural'; // Explicitly annotate type here to workaround API extractor's inability to handle `import('./someModule')` // type annotations when rolling up DTS file. var FormattedPluralWithIntl = injectIntl_1.default(FormattedPlural); exports.default = FormattedPluralWithIntl;