From 2fca7521de7c38a0e4a67704731073db008603aa Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 11:46:39 +0300 Subject: [PATCH 1/9] remove publish box translations from window object --- admin/formatter/class-metabox-formatter.php | 94 --------------------- 1 file changed, 94 deletions(-) diff --git a/admin/formatter/class-metabox-formatter.php b/admin/formatter/class-metabox-formatter.php index 782ab683d3c..699bc79b4bf 100644 --- a/admin/formatter/class-metabox-formatter.php +++ b/admin/formatter/class-metabox-formatter.php @@ -67,100 +67,6 @@ private function get_defaults() { 'articleTypeOptions' => $schema_types->get_article_type_options(), ], 'twitterCardType' => 'summary_large_image', - 'publish_box' => [ - 'labels' => [ - 'keyword' => [ - 'na' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */ - __( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Not available', 'wordpress-seo' ) . '' - ), - 'bad' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */ - __( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Needs improvement', 'wordpress-seo' ) . '' - ), - 'ok' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */ - __( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'OK', 'wordpress-seo' ) . '' - ), - 'good' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the SEO score. */ - __( '%1$sSEO%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Good', 'wordpress-seo' ) . '' - ), - ], - 'content' => [ - 'na' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */ - __( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Not available', 'wordpress-seo' ) . '' - ), - 'bad' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */ - __( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Needs improvement', 'wordpress-seo' ) . '' - ), - 'ok' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */ - __( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'OK', 'wordpress-seo' ) . '' - ), - 'good' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the readability score. */ - __( '%1$sReadability%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Good', 'wordpress-seo' ) . '' - ), - ], - 'inclusive-language' => [ - 'na' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */ - __( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Not available', 'wordpress-seo' ) . '' - ), - 'bad' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */ - __( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Needs improvement', 'wordpress-seo' ) . '' - ), - 'ok' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */ - __( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Potentially non-inclusive', 'wordpress-seo' ) . '' - ), - 'good' => sprintf( - /* translators: %1$s expands to the opening anchor tag, %2$s to the closing anchor tag, %3$s to the inclusive language score. */ - __( '%1$sInclusive language%2$s: %3$s', 'wordpress-seo' ), - '', - '', - '' . __( 'Good', 'wordpress-seo' ) . '' - ), - ], - ], - ], /** * Filter to determine if the markers should be enabled or not. * From 04426ae1974598fe8ad0b826793b5d84ccb5678f Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 11:52:39 +0300 Subject: [PATCH 2/9] moved translation to client side --- packages/js/src/ui/publishBox.js | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/js/src/ui/publishBox.js b/packages/js/src/ui/publishBox.js index 459029a4a46..322d72c9841 100644 --- a/packages/js/src/ui/publishBox.js +++ b/packages/js/src/ui/publishBox.js @@ -1,5 +1,6 @@ /* global wpseoScriptData */ import { get } from "lodash"; +import { __ } from "@wordpress/i18n"; var scoreDescriptionClass = "score-text"; var imageScoreClass = "image yoast-logo svg"; @@ -18,7 +19,40 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { if ( labels !== null ) { return get( labels, status, "" ); } - return get( wpseoScriptData, `metabox.publish_box.labels.${ scoreType }.${ status }`, "" ); + + const statusTranslatation = { + na: __( 'Not available', 'wordpress-seo' ), + bad:__( 'Needs improvement', 'wordpress-seo' ), + ok: __( 'OK', 'wordpress-seo' ), + good: __( 'Good', 'wordpress-seo' ), + }; + + const translations = { + keyword: { + label: __( 'SEO', 'wordpress-seo' ), + anchor: "yoast-seo-analysis-collapsible-metabox", + status: statusTranslatation, + }, + content: { + label: __( 'Readability', 'wordpress-seo' ), + anchor: "yoast-readability-analysis-collapsible-metabox", + status: statusTranslatation, + }, + 'inclusive-language': { + label: __( 'Inclusive language', 'wordpress-seo' ), + anchor: "yoast-inclusive-language-analysis-collapsible-metabox", + status: { + ...statusTranslatation, + ok: __( 'Potentially non-inclusive', 'wordpress-seo' ), + }, + }, + }; + + if( ! translations?.[scoreType]?.status?.[status] ) { + return ""; + } + + return `${translations[scoreType]?.label}: ${ translations[scoreType]?.status[status] }`; } /** From d6da3f6a070981e7278bd96d11cdedbec433fc0a Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 11:53:58 +0300 Subject: [PATCH 3/9] Match translation with block editor --- packages/js/src/ui/publishBox.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/js/src/ui/publishBox.js b/packages/js/src/ui/publishBox.js index 322d72c9841..628a5889a5c 100644 --- a/packages/js/src/ui/publishBox.js +++ b/packages/js/src/ui/publishBox.js @@ -1,6 +1,7 @@ /* global wpseoScriptData */ import { get } from "lodash"; import { __ } from "@wordpress/i18n"; +import { select } from "@wordpress/data"; var scoreDescriptionClass = "score-text"; var imageScoreClass = "image yoast-logo svg"; @@ -20,6 +21,8 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { return get( labels, status, "" ); } + const isPremium = select( "yoast-seo/editor" ).getIsPremium(); + const statusTranslatation = { na: __( 'Not available', 'wordpress-seo' ), bad:__( 'Needs improvement', 'wordpress-seo' ), @@ -29,17 +32,17 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { const translations = { keyword: { - label: __( 'SEO', 'wordpress-seo' ), + label: isPremium ? __( "Premium SEO analysis:", "wordpress-seo" ) : __( "SEO analysis:", "wordpress-seo" ), anchor: "yoast-seo-analysis-collapsible-metabox", status: statusTranslatation, }, content: { - label: __( 'Readability', 'wordpress-seo' ), + label: __( 'Readability analysis:', 'wordpress-seo' ), anchor: "yoast-readability-analysis-collapsible-metabox", status: statusTranslatation, }, 'inclusive-language': { - label: __( 'Inclusive language', 'wordpress-seo' ), + label: __( 'Inclusive language:', 'wordpress-seo' ), anchor: "yoast-inclusive-language-analysis-collapsible-metabox", status: { ...statusTranslatation, @@ -52,7 +55,7 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { return ""; } - return `${translations[scoreType]?.label}: ${ translations[scoreType]?.status[status] }`; + return `${translations[scoreType]?.label} ${ translations[scoreType]?.status[status] }`; } /** From 2a875f419f434db8df8c71fb25c056a81e9db3de Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 12:26:38 +0300 Subject: [PATCH 4/9] js fix lint --- packages/js/src/ui/publishBox.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/js/src/ui/publishBox.js b/packages/js/src/ui/publishBox.js index 628a5889a5c..eb48002c441 100644 --- a/packages/js/src/ui/publishBox.js +++ b/packages/js/src/ui/publishBox.js @@ -24,10 +24,10 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { const isPremium = select( "yoast-seo/editor" ).getIsPremium(); const statusTranslatation = { - na: __( 'Not available', 'wordpress-seo' ), - bad:__( 'Needs improvement', 'wordpress-seo' ), - ok: __( 'OK', 'wordpress-seo' ), - good: __( 'Good', 'wordpress-seo' ), + na: __( "Not available", "wordpress-seo" ), + bad: __( "Needs improvement", "wordpress-seo" ), + ok: __( "OK", "wordpress-seo" ), + good: __( "Good", "wordpress-seo" ), }; const translations = { @@ -37,25 +37,25 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { status: statusTranslatation, }, content: { - label: __( 'Readability analysis:', 'wordpress-seo' ), + label: __( "Readability analysis:", "wordpress-seo" ), anchor: "yoast-readability-analysis-collapsible-metabox", status: statusTranslatation, }, - 'inclusive-language': { - label: __( 'Inclusive language:', 'wordpress-seo' ), + "inclusive-language": { + label: __( "Inclusive language:", "wordpress-seo" ), anchor: "yoast-inclusive-language-analysis-collapsible-metabox", status: { ...statusTranslatation, - ok: __( 'Potentially non-inclusive', 'wordpress-seo' ), + ok: __( "Potentially non-inclusive", "wordpress-seo" ), }, }, }; - if( ! translations?.[scoreType]?.status?.[status] ) { + if ( ! translations?.[ scoreType ]?.status?.[ status ] ) { return ""; } - return `${translations[scoreType]?.label} ${ translations[scoreType]?.status[status] }`; + return `${translations[ scoreType ]?.label} ${ translations[ scoreType ]?.status[ status ] }`; } /** From 1bdb173193682d03c27fcbf4b7c851d8abb88ea2 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 13:22:14 +0300 Subject: [PATCH 5/9] fix typo --- packages/js/src/ui/publishBox.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/js/src/ui/publishBox.js b/packages/js/src/ui/publishBox.js index eb48002c441..073b1d115cc 100644 --- a/packages/js/src/ui/publishBox.js +++ b/packages/js/src/ui/publishBox.js @@ -23,7 +23,7 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { const isPremium = select( "yoast-seo/editor" ).getIsPremium(); - const statusTranslatation = { + const statusTranslation = { na: __( "Not available", "wordpress-seo" ), bad: __( "Needs improvement", "wordpress-seo" ), ok: __( "OK", "wordpress-seo" ), @@ -34,18 +34,18 @@ function createSEOScoreLabel( scoreType, status, labels = null ) { keyword: { label: isPremium ? __( "Premium SEO analysis:", "wordpress-seo" ) : __( "SEO analysis:", "wordpress-seo" ), anchor: "yoast-seo-analysis-collapsible-metabox", - status: statusTranslatation, + status: statusTranslation, }, content: { label: __( "Readability analysis:", "wordpress-seo" ), anchor: "yoast-readability-analysis-collapsible-metabox", - status: statusTranslatation, + status: statusTranslation, }, "inclusive-language": { label: __( "Inclusive language:", "wordpress-seo" ), anchor: "yoast-inclusive-language-analysis-collapsible-metabox", status: { - ...statusTranslatation, + ...statusTranslation, ok: __( "Potentially non-inclusive", "wordpress-seo" ), }, }, From 8df865881f443714c4d5b494e3135130cb5c1920 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 13:55:52 +0300 Subject: [PATCH 6/9] Changed the order of analysis scores in pre publish and document sidebar. Match the collapsable menu order and the classic editor order. --- packages/js/src/containers/DocumentSidebar.js | 2 +- packages/js/src/containers/PrePublish.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/js/src/containers/DocumentSidebar.js b/packages/js/src/containers/DocumentSidebar.js index 91470fdc29a..386446dac79 100644 --- a/packages/js/src/containers/DocumentSidebar.js +++ b/packages/js/src/containers/DocumentSidebar.js @@ -20,8 +20,8 @@ export function mapSelectToProps( select ) { const checklist = []; - maybeAddReadabilityCheck( checklist, yoastStore ); maybeAddSEOCheck( checklist, yoastStore ); + maybeAddReadabilityCheck( checklist, yoastStore ); maybeAddInclusiveLanguageCheck( checklist, yoastStore ); checklist.push( ...Object.values( yoastStore.getChecklistItems() ) ); diff --git a/packages/js/src/containers/PrePublish.js b/packages/js/src/containers/PrePublish.js index 411650d59f0..983bfb9738f 100644 --- a/packages/js/src/containers/PrePublish.js +++ b/packages/js/src/containers/PrePublish.js @@ -22,8 +22,9 @@ export function mapSelectToProps( select ) { const checklist = []; maybeAddFocusKeyphraseCheck( checklist, yoastStore ); - maybeAddReadabilityCheck( checklist, yoastStore ); + maybeAddSEOCheck( checklist, yoastStore ); + maybeAddReadabilityCheck( checklist, yoastStore ); maybeAddInclusiveLanguageCheck( checklist, yoastStore ); checklist.push( ...Object.values( yoastStore.getChecklistItems() ) ); From 0c5768dd28e368f0d24843aad217994ebf0d5bae Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 14:29:26 +0300 Subject: [PATCH 7/9] fixed na labels --- packages/js/src/analysis/getIndicatorForScore.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/js/src/analysis/getIndicatorForScore.js b/packages/js/src/analysis/getIndicatorForScore.js index 3f6852c6dfc..2eb188401bb 100644 --- a/packages/js/src/analysis/getIndicatorForScore.js +++ b/packages/js/src/analysis/getIndicatorForScore.js @@ -14,9 +14,9 @@ function getIndicatorForRating( rating ) { case "feedback": return { className: "na", - screenReaderText: __( "Feedback", "wordpress-seo" ), - screenReaderReadabilityText: "", - screenReaderInclusiveLanguageText: "", + screenReaderText: __( "Not available", "wordpress-seo" ), + screenReaderReadabilityText: __( "Not available", "wordpress-seo" ), + screenReaderInclusiveLanguageText: __( "Not available", "wordpress-seo" ), }; case "bad": return { From 2cab8e5194070085692a98d5387ad93a1a0442fd Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 14:39:32 +0300 Subject: [PATCH 8/9] js fix lint --- packages/js/src/containers/PrePublish.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/js/src/containers/PrePublish.js b/packages/js/src/containers/PrePublish.js index 983bfb9738f..2fcc73d63b1 100644 --- a/packages/js/src/containers/PrePublish.js +++ b/packages/js/src/containers/PrePublish.js @@ -22,7 +22,6 @@ export function mapSelectToProps( select ) { const checklist = []; maybeAddFocusKeyphraseCheck( checklist, yoastStore ); - maybeAddSEOCheck( checklist, yoastStore ); maybeAddReadabilityCheck( checklist, yoastStore ); maybeAddInclusiveLanguageCheck( checklist, yoastStore ); From f5cc9daf2fdd3c3b182a7bf664afd2f59b29c761 Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 28 Aug 2024 15:54:50 +0300 Subject: [PATCH 9/9] add tests for createSEOScoreLabel --- packages/js/src/ui/publishBox.js | 2 +- packages/js/tests/ui/publishBox.test.js | 92 +++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 packages/js/tests/ui/publishBox.test.js diff --git a/packages/js/src/ui/publishBox.js b/packages/js/src/ui/publishBox.js index 073b1d115cc..8a41ea164f6 100644 --- a/packages/js/src/ui/publishBox.js +++ b/packages/js/src/ui/publishBox.js @@ -16,7 +16,7 @@ var $ = jQuery; * * @returns {String} A string with label and description with correct text decoration. */ -function createSEOScoreLabel( scoreType, status, labels = null ) { +export function createSEOScoreLabel( scoreType, status, labels = null ) { if ( labels !== null ) { return get( labels, status, "" ); } diff --git a/packages/js/tests/ui/publishBox.test.js b/packages/js/tests/ui/publishBox.test.js new file mode 100644 index 00000000000..1d0d5e30183 --- /dev/null +++ b/packages/js/tests/ui/publishBox.test.js @@ -0,0 +1,92 @@ +import { select } from "@wordpress/data"; +import { get } from "lodash"; +import { createSEOScoreLabel } from "../../src/ui/publishBox"; + +jest.mock( "@wordpress/data", () => ( { + select: jest.fn(), +} ) ); + +jest.mock( "@wordpress/i18n", () => ( { + __: jest.fn( ( text ) => text ), +} ) ); + +jest.mock( "lodash", () => ( { + get: jest.fn(), +} ) ); + +describe( "createSEOScoreLabel", () => { + const mockSelect = select; + const mockGet = get; + + beforeEach( () => { + jest.clearAllMocks(); + } ); + + const dataProvider = [ + // Test case 1: labels are provided and status exists in labels + { + description: "returns label from provided labels when labels are provided", + scoreType: "keyword", + status: "good", + labels: { good: "Custom Good Label" }, + expectedResult: "Custom Good Label", + }, + // Test case 2: no labels provided, isPremium is false, status is 'good' + { + description: "returns correct label for keyword when isPremium is false and status is good", + scoreType: "keyword", + status: "good", + labels: null, + expectedResult: 'SEO analysis: Good', + isPremium: false, + }, + // Test case 3: no labels provided, isPremium is true, status is 'bad' + { + description: "returns correct label for keyword when isPremium is true and status is bad", + scoreType: "keyword", + status: "bad", + labels: null, + expectedResult: 'Premium SEO analysis: Needs improvement', + isPremium: true, + }, + // Test case 4: no labels provided, scoreType is 'content', status is 'na' + { + description: "returns correct label for content when status is na", + scoreType: "content", + status: "na", + labels: null, + expectedResult: 'Readability analysis: Not available', + isPremium: false, + }, + // Test case 5: no labels provided, scoreType is 'inclusive-language', status is 'ok' + { + description: "returns correct label for inclusive-language when status is ok", + scoreType: "inclusive-language", + status: "ok", + labels: null, + expectedResult: 'Inclusive language: Potentially non-inclusive', + isPremium: false, + }, + // Test case 6: no labels provided, invalid status + { + description: "returns empty string when status is invalid", + scoreType: "keyword", + status: "invalid-status", + labels: null, + expectedResult: "", + isPremium: false, + }, + ]; + + dataProvider.forEach( ( { description, scoreType, status, labels, expectedResult, isPremium } ) => { + test( description, () => { + mockGet.mockReturnValue( expectedResult ); + mockSelect.mockReturnValue( { + getIsPremium: () => isPremium, + } ); + + const result = createSEOScoreLabel( scoreType, status, labels ); + expect( result ).toBe( expectedResult ); + } ); + } ); +} );