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

Missing i18n for validation error messages and JavaScript messages #1368

Open
2 tasks done
pedro-mendonca opened this issue Mar 30, 2022 · 1 comment
Open
2 tasks done
Labels
[Type] Enhancement A suggestion for improvement.
Milestone

Comments

@pedro-mendonca
Copy link
Member

pedro-mendonca commented Mar 30, 2022

@pedro-mendonca
Copy link
Member Author

@ocean90 following up your comment:

For the validation part, I'm not sure why you added the $message parameter to the second position. This seems like an unnecessary back-compat break.
Building the message like this is also still cumbersome and not easy to translate since the sentence is split into multiple parts.
I think it would be much easier if the full message, one for positive and one for negative can be provided and only the type and field names are (optionally) injected.

Here is what I suggest for the validation notices (only added the actual message for the first example empty):

// Validation messages.
$messages = array(
	'empty'                                     => array(
		'positive' => sprintf(
			/* translators: 1: Type of a validation field. 2: Name of a validation field. */
			__( 'The %1$s %2$s is invalid and should be empty!', 'glotpress' ),
			$type_field,
			'<strong>' . $name_field . '</strong>'
		),
		'negative' => sprintf(
			/* translators: 1: Type of a validation field. 2: Name of a validation field. */
			__( 'The %1$s %2$s is invalid and should not be empty!', 'glotpress' ),
			$type_field,
			'<strong>' . $name_field . '</strong>'
		),
	),
	'empty_string'                              => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'positive_int'                              => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'int'                                       => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'null'                                      => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'between'                                   => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'between_exclusive'                         => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'one_of'                                    => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'consisting_only_of_ASCII_characters'       => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
	'starting_and_ending_with_a_word_character' => array(
		'positive' => 'the positive message',
		'negative' => 'the negative message',
	),
);

And then the current output logic:

if ( 'positive' === $rule['kind'] ) {
	return $messages[ $rule['rule'] ]['positive'];
} else { // if ( 'negative' == $rule['kind'] )
	return $messages[ $rule['rule'] ]['negative'];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants