From c14a1028cdcce5fa23b79cba8f2e2fc18686e6a2 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 29 Aug 2022 14:46:12 +0300 Subject: [PATCH] Lodash: Remove completely from i18n package --- package-lock.json | 1 - packages/i18n/package.json | 1 - packages/i18n/tools/pot-to-php.js | 15 +++++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index a045a86cd5b49..96b15cb29fbe1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17454,7 +17454,6 @@ "@babel/runtime": "^7.16.0", "@wordpress/hooks": "file:packages/hooks", "gettext-parser": "^1.3.1", - "lodash": "^4.17.21", "memize": "^1.1.0", "sprintf-js": "^1.1.1", "tannin": "^1.2.0" diff --git a/packages/i18n/package.json b/packages/i18n/package.json index cb7bb9d400270..25d00e177c68e 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -32,7 +32,6 @@ "@babel/runtime": "^7.16.0", "@wordpress/hooks": "file:../hooks", "gettext-parser": "^1.3.1", - "lodash": "^4.17.21", "memize": "^1.1.0", "sprintf-js": "^1.1.1", "tannin": "^1.2.0" diff --git a/packages/i18n/tools/pot-to-php.js b/packages/i18n/tools/pot-to-php.js index 78d52d0b54cec..1f371b539ae9c 100755 --- a/packages/i18n/tools/pot-to-php.js +++ b/packages/i18n/tools/pot-to-php.js @@ -4,7 +4,6 @@ * External dependencies */ const gettextParser = require( 'gettext-parser' ); -const { isEmpty } = require( 'lodash' ); const fs = require( 'fs' ); const TAB = '\t'; @@ -47,8 +46,8 @@ function convertTranslationToPHP( translation, textdomain, context = '' ) { let original = translation.msgid; const comments = translation.comments; - if ( ! isEmpty( comments ) ) { - if ( ! isEmpty( comments.reference ) ) { + if ( Object.values( comments ).length ) { + if ( comments.reference ) { // All references are split by newlines, add a // Reference prefix to make them tidy. php += TAB + @@ -59,7 +58,7 @@ function convertTranslationToPHP( translation, textdomain, context = '' ) { NEWLINE; } - if ( ! isEmpty( comments.translator ) ) { + if ( comments.translator ) { // All extracted comments are split by newlines, add a tab to line them up nicely. const translator = comments.translator .split( NEWLINE ) @@ -68,7 +67,7 @@ function convertTranslationToPHP( translation, textdomain, context = '' ) { php += TAB + `/* ${ translator } */${ NEWLINE }`; } - if ( ! isEmpty( comments.extracted ) ) { + if ( comments.extracted ) { php += TAB + `/* translators: ${ comments.extracted } */${ NEWLINE }`; } @@ -77,8 +76,8 @@ function convertTranslationToPHP( translation, textdomain, context = '' ) { if ( '' !== original ) { original = escapeSingleQuotes( original ); - if ( isEmpty( translation.msgid_plural ) ) { - if ( isEmpty( context ) ) { + if ( ! translation.msgid_plural ) { + if ( ! context ) { php += TAB + `__( '${ original }', '${ textdomain }' )`; } else { php += @@ -88,7 +87,7 @@ function convertTranslationToPHP( translation, textdomain, context = '' ) { } else { const plural = escapeSingleQuotes( translation.msgid_plural ); - if ( isEmpty( context ) ) { + if ( ! context ) { php += TAB + `_n_noop( '${ original }', '${ plural }', '${ textdomain }' )`;