Skip to content

Commit

Permalink
Merge pull request #21824 from Yoast/fix/translatability-sentence-and…
Browse files Browse the repository at this point in the history
…-paragraph-length

Improves the translatability of feedback for the paragraph and sentence length assessments
  • Loading branch information
FAMarfuaty authored Nov 19, 2024
2 parents 2ff7cf9 + 612e3dc commit 9f82943
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const expectedResults = {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains more than " +
"the recommended maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
"the recommended maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 5 of the paragraphs contain more than the " +
"recommended maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
"recommended maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const expectedResults = {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 3 of the paragraphs contain more than the recommended " +
"maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
"maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: " +
"1 of the paragraphs contains more than the recommended maximum of 150 words." +
"1 of the paragraphs contains more than the recommended maximum number of words (150)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 8 of the paragraphs contain more than the recommended" +
" maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
" maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const expectedResults = {
textParagraphTooLong: {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 6 of the paragraphs contain more than the recommended maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 6 of the paragraphs contain more than the recommended maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 4 of the paragraphs contain more " +
"than the recommended maximum of 300 characters. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
"than the recommended maximum number of characters (300). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const expectedResults = {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains more than the recommended" +
" maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
" maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 10 of the paragraphs contain more than the recommended" +
" maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
" maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const expectedResults = {
textParagraphTooLong: {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains more than the recommended maximum of 150 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
resultText: "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains more than the recommended maximum number of words (150). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ describe( "An assessment for scoring too long paragraphs.", function() {
const assessment = paragraphTooLongAssessment.getResult( paper, Factory.buildMockResearcher( [ { countLength: 160, text: "" } ] ) );
expect( assessment.getScore() ).toBe( 6 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs" +
" contains more than the recommended maximum of 150 words." +
" contains more than the recommended maximum number of words (150)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
it( "should score 1 extremely long paragraph", function() {
const assessment = paragraphTooLongAssessment.getResult( paper, Factory.buildMockResearcher( [ { countLength: 6000, text: "" } ] ) );
expect( assessment.getScore() ).toBe( 3 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs" +
" contains more than the recommended maximum of 150 words." +
" contains more than the recommended maximum number of words (150)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand All @@ -49,7 +49,7 @@ describe( "An assessment for scoring too long paragraphs.", function() {
{ countLength: 71, text: "" }, { countLength: 183, text: "" } ] ) );
expect( assessment.getScore() ).toBe( 6 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs" +
" contains more than the recommended maximum of 150 words." +
" contains more than the recommended maximum number of words (150)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand All @@ -58,7 +58,7 @@ describe( "An assessment for scoring too long paragraphs.", function() {
{ countLength: 191, text: "" }, { countLength: 183, text: "" } ] ) );
expect( assessment.getScore() ).toBe( 6 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 2 of the paragraphs" +
" contain more than the recommended maximum of 150 words." +
" contain more than the recommended maximum number of words (150)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand All @@ -77,7 +77,7 @@ describe( "An assessment for scoring too long paragraphs in Japanese in which ch
const assessment = paragraphTooLongAssessment.getResult( paper, new JapaneseResearcher( paper ) );
expect( assessment.getScore() ).toBe( 6 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs" +
" contains more than the recommended maximum of 300 characters." +
" contains more than the recommended maximum number of characters (300)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand All @@ -87,7 +87,7 @@ describe( "An assessment for scoring too long paragraphs in Japanese in which ch
const assessment = paragraphTooLongAssessment.getResult( paper, new JapaneseResearcher( paper ) );
expect( assessment.getScore() ).toBe( 3 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 1 of the paragraphs" +
" contains more than the recommended maximum of 300 characters." +
" contains more than the recommended maximum number of characters (300)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand All @@ -96,7 +96,7 @@ describe( "An assessment for scoring too long paragraphs in Japanese in which ch
const assessment = paragraphTooLongAssessment.getResult( paper, new JapaneseResearcher( paper ) );
expect( assessment.getScore() ).toBe( 6 );
expect( assessment.getText() ).toBe( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 2 of the paragraphs" +
" contain more than the recommended maximum of 300 characters." +
" contain more than the recommended maximum number of characters (300)." +
" <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
expect( assessment.hasMarks() ).toBe( true );
} );
Expand Down Expand Up @@ -318,7 +318,7 @@ describe( "A test for marking the sentences", function() {
} );

describe( "test for paragraph too long assessment when is used in product page analysis", function() {
it( "should assess a paper on a product page with paragraphs that contain less than 70 words", function() {
it( "should assess a paper on a product page with paragraphs that contain less than words (70)", function() {
const paper = new Paper( "" );
const config = {
parameters: {
Expand Down Expand Up @@ -350,7 +350,7 @@ describe( "test for paragraph too long assessment when is used in product page a
] ) );
expect( result.getScore() ).toEqual( 3 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 3 of the paragraphs contain" +
" more than the recommended maximum of 70 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
" more than the recommended maximum number of words (70). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
it( "should assess a paper on a product page with paragraphs that contain between 70 and 100 words", function() {
const paper = new Paper( "" );
Expand All @@ -367,14 +367,14 @@ describe( "test for paragraph too long assessment when is used in product page a
] ) );
expect( result.getScore() ).toEqual( 6 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 3 of the paragraphs contain " +
"more than the recommended maximum of 70 words. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
"more than the recommended maximum number of words (70). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
} );

describe( "test for paragraph too long assessment for languages that have language-specific config", () => {
// Japanese has a language specific config for paragraph length. The config is used for the unit tests below.
describe( "test for non-product pages", () => {
it( "should assess a paper with paragraphs that contain less than 300 characters (green bullet)", function() {
it( "should assess a paper with paragraphs that contain less than characters (300) (green bullet)", function() {
const paper = new Paper( "" );
const mockResearcher = Factory.buildMockResearcher( [
{ countLength: 200, text: "" },
Expand Down Expand Up @@ -404,7 +404,7 @@ describe( "test for paragraph too long assessment for languages that have langua

expect( result.getScore() ).toEqual( 3 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 2 of the paragraphs contain " +
"more than the recommended maximum of 300 characters. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
"more than the recommended maximum number of characters (300). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
it( "should assess a paper with paragraphs that contain 300-400 characters (orange bullet)", function() {
const paper = new Paper( "" );
Expand All @@ -420,11 +420,11 @@ describe( "test for paragraph too long assessment for languages that have langua

expect( result.getScore() ).toEqual( 6 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 2 of the paragraphs contain " +
"more than the recommended maximum of 300 characters. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
"more than the recommended maximum number of characters (300). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
} );
describe( "test for product pages", () => {
it( "should assess a paper with paragraphs that contain less than 140 characters (green bullet)", function() {
it( "should assess a paper with paragraphs that contain less than characters (140) (green bullet)", function() {
const paper = new Paper( "" );
const mockResearcher = Factory.buildMockResearcher( [
{ countLength: 100, text: "" },
Expand Down Expand Up @@ -454,7 +454,7 @@ describe( "test for paragraph too long assessment for languages that have langua

expect( result.getScore() ).toEqual( 3 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 3 of the paragraphs contain " +
"more than the recommended maximum of 140 characters. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
"more than the recommended maximum number of characters (140). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
it( "should assess a paper with all paragraphs that contain 140-200 characters (orange bullet)", function() {
const paper = new Paper( "" );
Expand All @@ -470,7 +470,7 @@ describe( "test for paragraph too long assessment for languages that have langua

expect( result.getScore() ).toEqual( 6 );
expect( result.getText() ).toEqual( "<a href='https://yoa.st/35d' target='_blank'>Paragraph length</a>: 3 of the paragraphs contain " +
"more than the recommended maximum of 140 characters. <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
"more than the recommended maximum number of characters (140). <a href='https://yoa.st/35e' target='_blank'>Shorten your paragraphs</a>!" );
} );
} );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe( "An assessment for sentence length", function() {
describe( "A test for getting the right scoring config", function() {
it( "uses the default config if no language-specific config is available", function() {
const defaultConfig = {
countTextIn: "words",
countCharacters: false,
recommendedLength: 20,
slightlyTooMany: 25,
farTooMany: 30,
Expand All @@ -310,7 +310,7 @@ describe( "A test for getting the right scoring config", function() {
} );
it( "uses the default config if no language-specific config is available in cornerstone", function() {
const defaultConfigCornerstone = {
countTextIn: "words",
countCharacters: false,
recommendedLength: 20,
slightlyTooMany: 20,
farTooMany: 25,
Expand All @@ -327,7 +327,7 @@ describe( "A test for getting the right scoring config", function() {
const mockPaper = new Paper( "" );
const researcher = new ItalianResearcher( mockPaper );
expect( new SentenceLengthInTextAssessment().getLanguageSpecificConfig( researcher ) ).toEqual( {
countTextIn: "words",
countCharacters: false,
recommendedLength: 25,
slightlyTooMany: 25,
farTooMany: 30,
Expand All @@ -341,7 +341,7 @@ describe( "A test for getting the right scoring config", function() {
slightlyTooMany: 20,
farTooMany: 25,
}, true ).getLanguageSpecificConfig( new PolishResearcher( mockPaper ) ) ).toEqual( {
countTextIn: "words",
countCharacters: false,
farTooMany: 20,
recommendedLength: 20,
slightlyTooMany: 15,
Expand All @@ -352,7 +352,7 @@ describe( "A test for getting the right scoring config", function() {
it( "uses a combination of language-specific and default config in cornerstone if there is regular but not cornerstone config" +
" available", function() {
const expectedConfig = {
countTextIn: "words",
countCharacters: false,
recommendedLength: 25,
slightlyTooMany: 20,
farTooMany: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const expectedResults = {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/shopify66' target='_blank'>Paragraph length</a>: 2 of the paragraphs contain more than " +
"the recommended maximum of 70 words. <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
"the recommended maximum number of words (70). <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const expectedResults = {
isApplicable: true,
score: 3,
resultText: "<a href='https://yoa.st/shopify66' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains " +
"more than the recommended maximum of 70 words. <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
"more than the recommended maximum number of words (70). <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const expectedResults = {
isApplicable: true,
score: 6,
resultText: "<a href='https://yoa.st/shopify66' target='_blank'>Paragraph length</a>: 1 of the paragraphs contains " +
"more than the recommended maximum of 70 words. <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
"more than the recommended maximum number of words (70). <a href='https://yoa.st/shopify67' target='_blank'>Shorten your paragraphs</a>!",
},
textSentenceLength: {
isApplicable: true,
Expand Down
Loading

0 comments on commit 9f82943

Please sign in to comment.