Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/i18n

Package Overview
Dependencies
Maintainers
5
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/i18n - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

benchmark/index.js

7

build-module/index.js

@@ -0,1 +1,2 @@

import _Object$assign from 'babel-runtime/core-js/object/assign';
/**

@@ -40,3 +41,3 @@ * External dependencies

i18n.options.locale_data[domain] = localeData;
i18n.options.locale_data[domain] = _Object$assign({}, i18n.options.locale_data[domain], localeData);
}

@@ -72,3 +73,3 @@

*/
export function dcnpgettext() {
export var dcnpgettext = memoize(function () {
var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';

@@ -87,3 +88,3 @@ var context = arguments[1];

}
}
});

@@ -90,0 +91,0 @@ /**

@@ -17,18 +17,23 @@ /**

// Domain name
"domain": "test_domain",
"lang": "fr",
domain: 'test_domain',
lang: 'fr',
// Plural form function for language
"plural_forms": "nplurals=2; plural=(n != 1);"
plural_forms: 'nplurals=2; plural=(n != 1);'
},
"hello": ["bonjour"],
hello: ['bonjour'],
'verb\x04feed': ["nourrir"],
'verb\x04feed': ['nourrir'],
"hello %s": ["bonjour %s"],
'hello %s': ['bonjour %s'],
"%d banana": ["une banane", "%d bananes"],
'%d banana': ['une banane', '%d bananes'],
'fruit\x04%d apple': ["une pomme", "%d pommes"]
'fruit\x04%d apple': ['une pomme', '%d pommes']
};
var additionalLocaleData = {
cheeseburger: ['hamburger au fromage'],
'%d cat': ['un chat', '%d chats']
};
setLocaleData(localeData, 'test_domain');

@@ -92,2 +97,33 @@

});
describe('setAdditionalLocale', function () {
beforeAll(function () {
setLocaleData(additionalLocaleData, 'test_domain');
});
describe('__', function () {
it('existing translation still available', function () {
expect(__('hello', 'test_domain')).toBe('bonjour');
});
});
describe('__', function () {
it('new translation available.', function () {
expect(__('cheeseburger', 'test_domain')).toBe('hamburger au fromage');
});
});
describe('_n', function () {
it('existing plural form still works', function () {
expect(_n('%d banana', '%d bananas', 3, 'test_domain')).toBe('%d bananes');
});
it('new singular form was added', function () {
expect(_n('%d cat', '%d cats', 1, 'test_domain')).toBe('un chat');
});
it('new plural form was added', function () {
expect(_n('%d cat', '%d cats', 3, 'test_domain')).toBe('%d chats');
});
});
});
});

@@ -6,5 +6,10 @@ 'use strict';

});
exports.dcnpgettext = undefined;
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
exports.setLocaleData = setLocaleData;
exports.getI18n = getI18n;
exports.dcnpgettext = dcnpgettext;
exports.__ = __;

@@ -62,3 +67,3 @@ exports._x = _x;

i18n.options.locale_data[domain] = localeData;
i18n.options.locale_data[domain] = (0, _assign2.default)({}, i18n.options.locale_data[domain], localeData);
}

@@ -94,3 +99,3 @@

*/
function dcnpgettext() {
var dcnpgettext = exports.dcnpgettext = (0, _memize2.default)(function () {
var domain = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';

@@ -109,3 +114,3 @@ var context = arguments[1];

}
}
});

@@ -112,0 +117,0 @@ /**

@@ -19,18 +19,23 @@ 'use strict';

// Domain name
"domain": "test_domain",
"lang": "fr",
domain: 'test_domain',
lang: 'fr',
// Plural form function for language
"plural_forms": "nplurals=2; plural=(n != 1);"
plural_forms: 'nplurals=2; plural=(n != 1);'
},
"hello": ["bonjour"],
hello: ['bonjour'],
'verb\x04feed': ["nourrir"],
'verb\x04feed': ['nourrir'],
"hello %s": ["bonjour %s"],
'hello %s': ['bonjour %s'],
"%d banana": ["une banane", "%d bananes"],
'%d banana': ['une banane', '%d bananes'],
'fruit\x04%d apple': ["une pomme", "%d pommes"]
'fruit\x04%d apple': ['une pomme', '%d pommes']
};
var additionalLocaleData = {
cheeseburger: ['hamburger au fromage'],
'%d cat': ['un chat', '%d chats']
};
(0, _.setLocaleData)(localeData, 'test_domain');

@@ -94,2 +99,33 @@

});
describe('setAdditionalLocale', function () {
beforeAll(function () {
(0, _.setLocaleData)(additionalLocaleData, 'test_domain');
});
describe('__', function () {
it('existing translation still available', function () {
expect((0, _.__)('hello', 'test_domain')).toBe('bonjour');
});
});
describe('__', function () {
it('new translation available.', function () {
expect((0, _.__)('cheeseburger', 'test_domain')).toBe('hamburger au fromage');
});
});
describe('_n', function () {
it('existing plural form still works', function () {
expect((0, _._n)('%d banana', '%d bananas', 3, 'test_domain')).toBe('%d bananes');
});
it('new singular form was added', function () {
expect((0, _._n)('%d cat', '%d cats', 1, 'test_domain')).toBe('un chat');
});
it('new plural form was added', function () {
expect((0, _._n)('%d cat', '%d cats', 3, 'test_domain')).toBe('%d chats');
});
});
});
});
{
"name": "@wordpress/i18n",
"version": "1.0.0",
"version": "1.1.0",
"description": "WordPress i18n library",

@@ -5,0 +5,0 @@ "author": "WordPress",

@@ -37,3 +37,7 @@ /**

i18n.options.locale_data[ domain ] = localeData;
i18n.options.locale_data[ domain ] = Object.assign(
{},
i18n.options.locale_data[ domain ],
localeData
);
}

@@ -69,3 +73,3 @@

*/
export function dcnpgettext( domain = 'default', context, single, plural, number ) {
export const dcnpgettext = memoize( ( domain = 'default', context, single, plural, number ) => {
try {

@@ -78,3 +82,3 @@ return getI18n().dcnpgettext( domain, context, single, plural, number );

}
}
} );

@@ -81,0 +85,0 @@ /**

@@ -13,18 +13,23 @@ /**

// Domain name
"domain" : "test_domain",
"lang" : "fr",
domain: 'test_domain',
lang: 'fr',
// Plural form function for language
"plural_forms" : "nplurals=2; plural=(n != 1);"
plural_forms: 'nplurals=2; plural=(n != 1);'
},
"hello" : [ "bonjour" ],
hello: [ 'bonjour' ],
"verb\u0004feed": [ "nourrir" ],
'verb\u0004feed': [ 'nourrir' ],
"hello %s": [ "bonjour %s"],
'hello %s': [ 'bonjour %s' ],
"%d banana" : [ "une banane", "%d bananes" ],
'%d banana': [ 'une banane', '%d bananes' ],
"fruit\u0004%d apple" : [ "une pomme", "%d pommes" ],
'fruit\u0004%d apple': [ 'une pomme', '%d pommes' ],
}
const additionalLocaleData = {
cheeseburger: [ 'hamburger au fromage' ],
'%d cat': [ 'un chat', '%d chats' ]
};
setLocaleData( localeData, 'test_domain' );

@@ -88,2 +93,33 @@

} );
describe( 'setAdditionalLocale', () => {
beforeAll( () => {
setLocaleData( additionalLocaleData, 'test_domain' );
} );
describe( '__', () => {
it( 'existing translation still available', () => {
expect( __( 'hello', 'test_domain' ) ).toBe( 'bonjour' );
} );
} );
describe( '__', () => {
it( 'new translation available.', () => {
expect( __( 'cheeseburger', 'test_domain' ) ).toBe( 'hamburger au fromage' );
} );
} );
describe( '_n', () => {
it( 'existing plural form still works', () => {
expect( _n( '%d banana', '%d bananas', 3, 'test_domain' ) ).toBe( '%d bananes' );
} );
it( 'new singular form was added', () => {
expect( _n( '%d cat', '%d cats', 1, 'test_domain' ) ).toBe( 'un chat' );
} );
it( 'new plural form was added', () => {
expect( _n( '%d cat', '%d cats', 3, 'test_domain' ) ).toBe( '%d chats' );
} );
} );
} );
} );
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc