Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the exact amount of spaces added or missing on the translation warnings #1490

Merged
merged 3 commits into from
Oct 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 53 additions & 7 deletions gp-includes/warnings.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,29 +842,75 @@ public function warning_unexpected_start_end_space( string $original, string $tr

$warnings = array();
if ( $original_start_spaces && ! $translation_start_spaces ) {
$warnings[] = __( 'The translation appears to be missing one or more spaces at the beginning.', 'glotpress' );
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the beginning of the original string. */
_n(
'The translation appears to be missing %d space at the beginning.',
'The translation appears to be missing %d spaces at the beginning.',
$original_start_spaces,
'glotpress'
),
$original_start_spaces
);
}
if ( ( ! $original_start_spaces ) && $translation_start_spaces ) {
$warnings[] = __( 'The translation appears to be adding one or more spaces at the beginning.', 'glotpress' );
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the beginning of the translation string. */
_n(
'The translation appears to be adding %d space at the beginning.',
'The translation appears to be adding %d spaces at the beginning.',
$translation_start_spaces,
'glotpress'
),
$translation_start_spaces
);
}
if ( ( $original_end_spaces ) && ( ! $translation_end_spaces ) ) {
$warnings[] = __( 'The translation appears to be missing one or more spaces at the end.', 'glotpress' );
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the end of the original string. */
_n(
'The translation appears to be missing %d space at the end.',
'The translation appears to be missing %d spaces at the end.',
$original_end_spaces,
'glotpress'
),
$original_end_spaces
);
}
if ( ! $original_end_spaces && $translation_end_spaces ) {
$warnings[] = __( 'The translation appears to be adding one or more spaces at the end.', 'glotpress' );
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the end of the translation string. */
_n(
'The translation appears to be adding %d space at the end.',
'The translation appears to be adding %d spaces at the end.',
$translation_end_spaces,
'glotpress'
),
$translation_end_spaces
);
}
if ( $original_start_spaces && $translation_start_spaces && ( $original_start_spaces !== $translation_start_spaces ) ) {
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the beginning of the original string. 2: Number of spaces at the beginning of the translation string. */
__( 'Expected %1$s space(s) at the beginning, got %2$s.', 'glotpress' ),
_n(
'Expected %1$d space at the beginning, got %2$d.',
'Expected %1$d spaces at the beginning, got %2$d.',
$original_start_spaces,
'glotpress'
),
$original_start_spaces,
$translation_start_spaces
);
}
if ( $original_end_spaces && $translation_end_spaces && ( $original_end_spaces !== $translation_end_spaces ) ) {
$warnings[] = sprintf(
/* translators: 1: Number of spaces at the end of the original string. 2: Number of spaces at the end of the translation string. */
__( 'Expected %1$s space(s) at the end, got %2$s.', 'glotpress' ),
/* translators: 1: Number of spaces at the end of the original string. 2: Number of spaces at the end of the translation string. */
_n(
'Expected %1$d space at the end, got %2$d.',
'Expected %1$d spaces at the end, got %2$d.',
$original_end_spaces,
'glotpress'
),
$original_end_spaces,
$translation_end_spaces
);
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/testcases/test_builtin_warnings.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,43 +670,43 @@ public function test_unexpected_start_end_space() {
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
' Original string',
'Cadea traducida',
'The translation appears to be missing one or more spaces at the beginning.' );
'The translation appears to be missing 1 space at the beginning.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
'Original string',
' Cadea traducida',
'The translation appears to be adding one or more spaces at the beginning.' );
'The translation appears to be adding 1 space at the beginning.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
'Original string ',
'Cadea traducida',
'The translation appears to be missing one or more spaces at the end.' );
'The translation appears to be missing 1 space at the end.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
'Original string',
'Cadea traducida ',
'The translation appears to be adding one or more spaces at the end.' );
'The translation appears to be adding 1 space at the end.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
' Original string',
' Cadea traducida',
'Expected 1 space(s) at the beginning, got 3.' );
'Expected 1 space at the beginning, got 3.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
' Original string',
' Cadea traducida',
'Expected 3 space(s) at the beginning, got 1.' );
'Expected 3 spaces at the beginning, got 1.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
'Original string ',
'Cadea traducida ',
'Expected 1 space(s) at the end, got 3.' );
'Expected 1 space at the end, got 3.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
'Original string ',
'Cadea traducida ',
'Expected 3 space(s) at the end, got 1.' );
'Expected 3 spaces at the end, got 1.' );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
' Original string ',
' Cadea traducida ',
"Expected 3 space(s) at the beginning, got 1.\nExpected 3 space(s) at the end, got 1." );
"Expected 3 spaces at the beginning, got 1.\nExpected 3 spaces at the end, got 1." );
$this->assertHasWarningsAndContainsOutput( 'unexpected_start_end_space',
' Original string ',
' Cadea traducida ',
"Expected 1 space(s) at the beginning, got 3.\nExpected 1 space(s) at the end, got 3." );
"Expected 1 space at the beginning, got 3.\nExpected 1 space at the end, got 3." );
}

public function test_chained_warnings() {
Expand Down Expand Up @@ -900,7 +900,7 @@ public function test_chained_warnings() {
array(
'tags' => 'Missing tags from translation. Expected: <p> </p>',
'placeholders' => 'Extra %% placeholder in translation.',
'unexpected_start_end_space' => "The translation appears to be missing one or more spaces at the beginning.\nThe translation appears to be adding one or more spaces at the end."
'unexpected_start_end_space' => "The translation appears to be missing 1 space at the beginning.\nThe translation appears to be adding 1 space at the end."
),
)
);
Expand All @@ -912,7 +912,7 @@ public function test_chained_warnings() {
array(
'tags' => 'Missing tags from translation. Expected: <p> </p>',
'placeholders' => 'Extra %% placeholder in translation.',
'unexpected_start_end_space' => "Expected 4 space(s) at the beginning, got 1.\nExpected 1 space(s) at the end, got 5."
'unexpected_start_end_space' => "Expected 4 spaces at the beginning, got 1.\nExpected 1 space at the end, got 5."
),
)
);
Expand Down