Skip to content

Commit

Permalink
Merge pull request #21568 from Yoast/21562-remove-publish_box-transla…
Browse files Browse the repository at this point in the history
…tions-from-class-metabox-formatter

21562 remove publish box translations from class metabox formatter
  • Loading branch information
thijsoo committed Aug 28, 2024
2 parents 4baef28 + f5cc9da commit d4a1502
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 101 deletions.
94 changes: 0 additions & 94 deletions admin/formatter/class-metabox-formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'OK', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-seo-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
'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' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'OK', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-readability-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
'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' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Not available', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Needs improvement', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Potentially non-inclusive', 'wordpress-seo' ) . '</strong>'
),
'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' ),
'<a href="#yoast-inclusive-language-analysis-collapsible-metabox">',
'</a>',
'<strong>' . __( 'Good', 'wordpress-seo' ) . '</strong>'
),
],
],
],
/**
* Filter to determine if the markers should be enabled or not.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/js/src/analysis/getIndicatorForScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/containers/DocumentSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/containers/PrePublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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() ) );
Expand Down
41 changes: 39 additions & 2 deletions packages/js/src/ui/publishBox.js
Original file line number Diff line number Diff line change
@@ -1,5 +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";
Expand All @@ -14,11 +16,46 @@ 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, "" );
}
return get( wpseoScriptData, `metabox.publish_box.labels.${ scoreType }.${ status }`, "" );

const isPremium = select( "yoast-seo/editor" ).getIsPremium();

const statusTranslation = {
na: __( "Not available", "wordpress-seo" ),
bad: __( "Needs improvement", "wordpress-seo" ),
ok: __( "OK", "wordpress-seo" ),
good: __( "Good", "wordpress-seo" ),
};

const translations = {
keyword: {
label: isPremium ? __( "Premium SEO analysis:", "wordpress-seo" ) : __( "SEO analysis:", "wordpress-seo" ),
anchor: "yoast-seo-analysis-collapsible-metabox",
status: statusTranslation,
},
content: {
label: __( "Readability analysis:", "wordpress-seo" ),
anchor: "yoast-readability-analysis-collapsible-metabox",
status: statusTranslation,
},
"inclusive-language": {
label: __( "Inclusive language:", "wordpress-seo" ),
anchor: "yoast-inclusive-language-analysis-collapsible-metabox",
status: {
...statusTranslation,
ok: __( "Potentially non-inclusive", "wordpress-seo" ),
},
},
};

if ( ! translations?.[ scoreType ]?.status?.[ status ] ) {
return "";
}

return `<a href="#${translations[ scoreType ]?.anchor}">${translations[ scoreType ]?.label}</a> <strong>${ translations[ scoreType ]?.status[ status ] }</strong>`;
}

/**
Expand Down
92 changes: 92 additions & 0 deletions packages/js/tests/ui/publishBox.test.js
Original file line number Diff line number Diff line change
@@ -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: '<a href="#yoast-seo-analysis-collapsible-metabox">SEO analysis:</a> <strong>Good</strong>',
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: '<a href="#yoast-seo-analysis-collapsible-metabox">Premium SEO analysis:</a> <strong>Needs improvement</strong>',
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: '<a href="#yoast-readability-analysis-collapsible-metabox">Readability analysis:</a> <strong>Not available</strong>',
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: '<a href="#yoast-inclusive-language-analysis-collapsible-metabox">Inclusive language:</a> <strong>Potentially non-inclusive</strong>',
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 );
} );
} );
} );

0 comments on commit d4a1502

Please sign in to comment.