UNPKG

@skoging/react-intl-po

Version:

Extract POT from react-intl and convert back to json.

55 lines (47 loc) 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var R = _interopRequireWildcard(require("ramda")); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /** * Create a POT header string * @param {Object} options * @param {String|String[]} [options.comments] * @param {Date} [options.potCreationDate] used for POT-Creation-Date * @param {String} [options.projectIdVersion] Project-Id-Version * @param {String} [options.charset] * @param {String} [options.encoding] * @param {String} [options.language] * @return {String} potSource * * example: see tests * * @see https://www.gnu.org/software/trans-coord/manual/gnun/html_node/PO-Header.html * @author Guillaume Boddaert */ const potHeader = (options = {}) => { const o = R.evolve({ comments: R.pipe(R.cond([[R.is(Array), R.identity], [R.is(String), R.of]]), R.map(R.split('\n')), R.flatten, R.map(e => `# ${e}`), R.join('\n')), projectIdVersion: e => `"Project-Id-Version: ${e}\\n"`, potCreationDate: e => `"POT-Creation-Date: ${e.toISOString()}\\n"`, charset: e => `"Content-Type: text/plain; charset=${e}\\n"`, encoding: e => `"Content-Transfer-Encoding: ${e}\\n"`, language: e => e && `"Language: ${e}\\n"` })(options); return `${o.comments} msgid "" msgstr "" ${o.projectIdVersion} ${o.potCreationDate} ${o.charset} ${o.encoding} "MIME-Version: 1.0\\n" "X-Generator: react-intl-po\\n" ${o.language} `.replace(/undefined\r?\n|\r/g, ''); }; var _default = potHeader; exports.default = _default;