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

Wrong error message for translations with a missing set ID #341

Closed
ocean90 opened this issue Mar 14, 2016 · 4 comments
Closed

Wrong error message for translations with a missing set ID #341

ocean90 opened this issue Mar 14, 2016 · 4 comments
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature is broken.
Milestone

Comments

@ocean90
Copy link
Member

ocean90 commented Mar 14, 2016

Noticed this while working on #311.

$data = array(
    'user_id'            => 1,
    'original_id'        => 1,
    'status'             => 'current',
);
$plurals = array(
    'translation_0' => 'Zero',
    'translation_1' => '',
    'translation_2' => '',
    'translation_3' => '',
    'translation_4' => '',
    'translation_5' => '',
);

$data = array_merge( $data, $plurals );

$translation = $this->factory->translation->create( $data );
$this->assertFalse( $translation->validate() );
var_dump( $translation->errors );

Result of the var_dump():

array(6) {
  [0]=>
  string(82) "The textarea <strong>Translation 1</strong> is invalid and should be positive int!"
  [1]=>
  string(86) "The textarea <strong>Translation 2</strong> is invalid and should not be empty string!"
  [2]=>
  string(86) "The textarea <strong>Translation 3</strong> is invalid and should not be empty string!"
  [3]=>
  string(86) "The textarea <strong>Translation 4</strong> is invalid and should not be empty string!"
  [4]=>
  string(86) "The textarea <strong>Translation 5</strong> is invalid and should not be empty string!"
  [5]=>
  string(86) "The textarea <strong>Translation 6</strong> is invalid and should not be empty string!"
}

The first error message is wrong.

@toolstack
Copy link
Contributor

Won't it be the right message after #311?

@ocean90
Copy link
Member Author

ocean90 commented Mar 14, 2016

The textarea Translation 1 is invalid and should be positive int!

That should be something like "The translation_set_id is invalid and should be positive int!"

@toolstack
Copy link
Contributor

Ah, I see it now 😄.

@ocean90 ocean90 added the [Type] Bug An existing feature is broken. label Mar 15, 2016
@ocean90 ocean90 modified the milestone: 2.1 Apr 1, 2016
@toolstack
Copy link
Contributor

Found the issue, https://github.com/GlotPress/GlotPress-WP/blob/develop/gp-includes/validation.php#L152 is:

if( strpos( $name_field, 'translation_' ) === 0 ) {

which matches translation_set_id as well as translation_0, etc.

Need to replace it with a better matching function like:

if( 1 === preg_match( '/translation_[0-9]/', $name_field ) ) {

@toolstack toolstack added the [Status] In Progress Tracking issues with work in progress label May 17, 2016
@toolstack toolstack self-assigned this May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature is broken.
Projects
None yet
Development

No branches or pull requests

2 participants