Repository URL to install this package:
|
Version:
4.0.0-alpha.2 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.translate = translate;
exports.translateMenuItems = translateMenuItems;
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* This file contains helpers for translating react-intl messages, but only
* if an intl object exists. intl needs to be supplied by the consuming project,
* but can be null when e.g. rendering the style guide, which we want to handle
* gracefully by displaying the default untranslated message.
*/
/**
* Optionally translate one message.
*
* @param {string} message The react-intl message.
* @param {Object} intl The intl object injected by react-intl.
*/
function translate(message, intl) {
return intl ? intl.formatMessage(message) : message.defaultMessage;
}
/**
* Optionally translate an array of menu items.
*
* @param {Object[]} items An array of menu item description objects.
* @param {Object} intl The intl object injected by react-intl.
*/
function translateMenuItems(items, intl) {
return items.map(function (item) {
return _objectSpread({}, item, {
label: translate(item.label, intl)
});
});
}