Skip to content
This repository has been archived by the owner on Jul 9, 2018. It is now read-only.

i18n: Memoize dcnpgettext #101

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/i18n/benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Benchmark = require( 'benchmark' );
const { __ } = require( '../' );

const suite = new Benchmark.Suite;

suite
.add( '__', () => {
__( 'Translate' );
} )
.on( 'cycle', ( event ) => console.log( event.target.toString() ) )
.run( { async: true } );
4 changes: 2 additions & 2 deletions packages/i18n/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export function getI18n() {
*
* @return {string} The translated string.
*/
export function dcnpgettext( domain = 'default', context, single, plural, number ) {
export const dcnpgettext = memoize( ( domain = 'default', context, single, plural, number ) => {
try {
return getI18n().dcnpgettext( domain, context, single, plural, number );
} catch ( error ) {
logErrorOnce( 'Jed localization error: \n\n' + error.toString() );

return single;
}
}
} );

/**
* Retrieve the translation of text.
Expand Down