@wordpress/i18n
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -10,3 +10,4 @@ const Benchmark = require( 'benchmark' ); | ||
} ) | ||
// eslint-disable-next-line no-console | ||
.on( 'cycle', ( event ) => console.log( event.target.toString() ) ) | ||
.run( { async: true } ); |
@@ -1,2 +0,4 @@ | ||
import _Object$assign from 'babel-runtime/core-js/object/assign'; | ||
import "core-js/modules/es6.regexp.to-string"; | ||
import _Object$assign from "@babel/runtime/core-js/object/assign"; | ||
/** | ||
@@ -7,5 +9,3 @@ * External dependencies | ||
import memoize from 'memize'; | ||
var i18n = void 0; | ||
var i18n; | ||
/** | ||
@@ -18,2 +18,3 @@ * Log to console, once per message; or more precisely, per referentially equal | ||
*/ | ||
var logErrorOnce = memoize(console.error); // eslint-disable-line no-console | ||
@@ -30,4 +31,7 @@ | ||
*/ | ||
export function setLocaleData() { | ||
var localeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { '': {} }; | ||
var localeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { | ||
'': {} | ||
}; | ||
var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default'; | ||
@@ -46,3 +50,2 @@ | ||
} | ||
/** | ||
@@ -54,2 +57,3 @@ * Returns the current Jed instance, initializing with a default configuration | ||
*/ | ||
export function getI18n() { | ||
@@ -62,3 +66,2 @@ if (!i18n) { | ||
} | ||
/** | ||
@@ -78,8 +81,9 @@ * Wrapper for Jed's `dcnpgettext`, its most qualified function. Absorbs errors | ||
*/ | ||
export var dcnpgettext = memoize(function () { | ||
var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default'; | ||
var context = arguments[1]; | ||
var single = arguments[2]; | ||
var plural = arguments[3]; | ||
var number = arguments[4]; | ||
var context = arguments.length > 1 ? arguments[1] : undefined; | ||
var single = arguments.length > 2 ? arguments[2] : undefined; | ||
var plural = arguments.length > 3 ? arguments[3] : undefined; | ||
var number = arguments.length > 4 ? arguments[4] : undefined; | ||
@@ -90,7 +94,5 @@ try { | ||
logErrorOnce('Jed localization error: \n\n' + error.toString()); | ||
return single; | ||
} | ||
}); | ||
/** | ||
@@ -106,6 +108,6 @@ * Retrieve the translation of text. | ||
*/ | ||
export function __(text, domain) { | ||
return dcnpgettext(domain, undefined, text); | ||
} | ||
/** | ||
@@ -122,6 +124,6 @@ * Retrieve translated string with gettext context. | ||
*/ | ||
export function _x(text, context, domain) { | ||
return dcnpgettext(domain, context, text); | ||
} | ||
/** | ||
@@ -141,6 +143,6 @@ * Translates and retrieves the singular or plural form based on the supplied | ||
*/ | ||
export function _n(single, plural, number, domain) { | ||
return dcnpgettext(domain, undefined, single, plural, number); | ||
} | ||
/** | ||
@@ -161,6 +163,6 @@ * Translates and retrieves the singular or plural form based on the supplied | ||
*/ | ||
export function _nx(single, plural, number, context, domain) { | ||
return dcnpgettext(domain, context, single, plural, number); | ||
} | ||
/** | ||
@@ -177,5 +179,6 @@ * Returns a formatted string. If an error occurs in applying the format, the | ||
*/ | ||
export function sprintf(format) { | ||
try { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
@@ -187,5 +190,4 @@ } | ||
logErrorOnce('Jed sprintf error: \n\n' + error.toString()); | ||
return format; | ||
} | ||
} |
@@ -1,12 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.dcnpgettext = undefined; | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
exports.setLocaleData = setLocaleData; | ||
@@ -19,18 +15,16 @@ exports.getI18n = getI18n; | ||
exports.sprintf = sprintf; | ||
exports.dcnpgettext = void 0; | ||
var _jed = require('jed'); | ||
require("core-js/modules/es6.regexp.to-string"); | ||
var _jed2 = _interopRequireDefault(_jed); | ||
var _assign = _interopRequireDefault(require("@babel/runtime/core-js/object/assign")); | ||
var _memize = require('memize'); | ||
var _jed = _interopRequireDefault(require("jed")); | ||
var _memize2 = _interopRequireDefault(_memize); | ||
var _memize = _interopRequireDefault(require("memize")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* External dependencies | ||
*/ | ||
var i18n = void 0; | ||
var i18n; | ||
/** | ||
@@ -43,4 +37,5 @@ * Log to console, once per message; or more precisely, per referentially equal | ||
*/ | ||
var logErrorOnce = (0, _memize2.default)(console.error); // eslint-disable-line no-console | ||
var logErrorOnce = (0, _memize.default)(console.error); // eslint-disable-line no-console | ||
/** | ||
@@ -55,8 +50,11 @@ * Merges locale data into the Jed instance by domain. Creates a new Jed | ||
*/ | ||
function setLocaleData() { | ||
var localeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { '': {} }; | ||
var localeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { | ||
'': {} | ||
}; | ||
var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default'; | ||
if (!i18n) { | ||
i18n = new _jed2.default({ | ||
i18n = new _jed.default({ | ||
domain: 'default', | ||
@@ -69,5 +67,4 @@ locale_data: { | ||
i18n.options.locale_data[domain] = (0, _assign2.default)({}, i18n.options.locale_data[domain], localeData); | ||
i18n.options.locale_data[domain] = (0, _assign.default)({}, i18n.options.locale_data[domain], localeData); | ||
} | ||
/** | ||
@@ -79,2 +76,4 @@ * Returns the current Jed instance, initializing with a default configuration | ||
*/ | ||
function getI18n() { | ||
@@ -87,3 +86,2 @@ if (!i18n) { | ||
} | ||
/** | ||
@@ -103,8 +101,10 @@ * Wrapper for Jed's `dcnpgettext`, its most qualified function. Absorbs errors | ||
*/ | ||
var dcnpgettext = exports.dcnpgettext = (0, _memize2.default)(function () { | ||
var dcnpgettext = (0, _memize.default)(function () { | ||
var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default'; | ||
var context = arguments[1]; | ||
var single = arguments[2]; | ||
var plural = arguments[3]; | ||
var number = arguments[4]; | ||
var context = arguments.length > 1 ? arguments[1] : undefined; | ||
var single = arguments.length > 2 ? arguments[2] : undefined; | ||
var plural = arguments.length > 3 ? arguments[3] : undefined; | ||
var number = arguments.length > 4 ? arguments[4] : undefined; | ||
@@ -115,7 +115,5 @@ try { | ||
logErrorOnce('Jed localization error: \n\n' + error.toString()); | ||
return single; | ||
} | ||
}); | ||
/** | ||
@@ -131,6 +129,8 @@ * Retrieve the translation of text. | ||
*/ | ||
exports.dcnpgettext = dcnpgettext; | ||
function __(text, domain) { | ||
return dcnpgettext(domain, undefined, text); | ||
} | ||
/** | ||
@@ -147,6 +147,7 @@ * Retrieve translated string with gettext context. | ||
*/ | ||
function _x(text, context, domain) { | ||
return dcnpgettext(domain, context, text); | ||
} | ||
/** | ||
@@ -166,6 +167,7 @@ * Translates and retrieves the singular or plural form based on the supplied | ||
*/ | ||
function _n(single, plural, number, domain) { | ||
return dcnpgettext(domain, undefined, single, plural, number); | ||
} | ||
/** | ||
@@ -186,6 +188,7 @@ * Translates and retrieves the singular or plural form based on the supplied | ||
*/ | ||
function _nx(single, plural, number, context, domain) { | ||
return dcnpgettext(domain, context, single, plural, number); | ||
} | ||
/** | ||
@@ -202,14 +205,15 @@ * Returns a formatted string. If an error occurs in applying the format, the | ||
*/ | ||
function sprintf(format) { | ||
try { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return _jed2.default.sprintf.apply(_jed2.default, [format].concat(args)); | ||
return _jed.default.sprintf.apply(_jed.default, [format].concat(args)); | ||
} catch (error) { | ||
logErrorOnce('Jed sprintf error: \n\n' + error.toString()); | ||
return format; | ||
} | ||
} |
@@ -0,3 +1,8 @@ | ||
## 1.2.0 (2018-07-12) | ||
- Updated build to work with Babel 7 ([#7832](https://github.com/WordPress/gutenberg/pull/7832)) | ||
- Moved `@WordPress/packages` repository to `@WordPress/gutenberg` ([#7805](https://github.com/WordPress/gutenberg/pull/7805)) | ||
## 1.1.1 (2018-05-18) | ||
- Fix: Standardized `package.json` format ([#119](https://github.com/WordPress/packages/pull/119)) |
{ | ||
"name": "@wordpress/i18n", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "WordPress i18n library", | ||
"author": "WordPress", | ||
"author": "The WordPress Contributors", | ||
"license": "GPL-2.0-or-later", | ||
"keywords": [ | ||
"wordpress", | ||
"i18n" | ||
], | ||
"homepage": "https://github.com/WordPress/packages/tree/master/packages/i18n/README.md", | ||
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/i18n/README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/WordPress/packages.git" | ||
"url": "https://github.com/WordPress/gutenberg.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/WordPress/packages/issues" | ||
"url": "https://github.com/WordPress/gutenberg/issues" | ||
}, | ||
@@ -26,8 +27,12 @@ "main": "build/index.js", | ||
"jed": "^1.1.1", | ||
"lodash": "^4.17.5", | ||
"lodash": "^4.17.10", | ||
"memize": "^1.0.5" | ||
}, | ||
"devDependencies": { | ||
"benchmark": "^2.1.4" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
}, | ||
"gitHead": "8827c049ec802471f51a5cb906d9096ffc1b4e48" | ||
} |
@@ -11,3 +11,3 @@ /** | ||
const localeData = { | ||
"" : { | ||
'': { | ||
// Domain name | ||
@@ -17,3 +17,3 @@ domain: 'test_domain', | ||
// Plural form function for language | ||
plural_forms: 'nplurals=2; plural=(n != 1);' | ||
plural_forms: 'nplurals=2; plural=(n != 1);', | ||
}, | ||
@@ -30,6 +30,6 @@ | ||
'fruit\u0004%d apple': [ 'une pomme', '%d pommes' ], | ||
} | ||
}; | ||
const additionalLocaleData = { | ||
cheeseburger: [ 'hamburger au fromage' ], | ||
'%d cat': [ 'un chat', '%d chats' ] | ||
'%d cat': [ 'un chat', '%d chats' ], | ||
}; | ||
@@ -90,3 +90,3 @@ | ||
it( 'replaces placeholders', () => { | ||
const result = sprintf( __( 'hello %s', 'test_domain'), 'Riad' ); | ||
const result = sprintf( __( 'hello %s', 'test_domain' ), 'Riad' ); | ||
@@ -105,5 +105,3 @@ expect( result ).toBe( 'bonjour Riad' ); | ||
} ); | ||
} ); | ||
describe( '__', () => { | ||
it( 'new translation available.', () => { | ||
@@ -110,0 +108,0 @@ expect( __( 'cheeseburger', 'test_domain' ) ).toBe( 'hamburger au fromage' ); |
@@ -5,3 +5,2 @@ #!/usr/bin/env node | ||
const { isEmpty } = require( 'lodash' ); | ||
const path = require( 'path' ); | ||
const fs = require( 'fs' ); | ||
@@ -106,3 +105,3 @@ | ||
.map( ( translation ) => convertTranslationToPHP( translation, options.textdomain, context ) ) | ||
.filter( php => php !== '' ); | ||
.filter( ( php ) => php !== '' ); | ||
@@ -117,3 +116,3 @@ output = [ ...output, ...newOutput ]; | ||
const args = process.argv.slice(2); | ||
const args = process.argv.slice( 2 ); | ||
@@ -124,4 +123,4 @@ convertPOTToPHP( | ||
{ | ||
textdomain: args[ 2 ] | ||
textdomain: args[ 2 ], | ||
} | ||
); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
28032
1
9
695
Updatedlodash@^4.17.10