So basically, the default message for notEmpty is "This field is required."
Is there a practical way to do internationalization other than overriding ValidateOptions::inst()->message()
thanks
Yup, that's basically it. How else could it be done? Possibly return a token and have that token looked up? Then you'd need to have a list of the tokens and you might as well do the lookup at the server-side?
Yes token based solution is what I am looking for. I am using i18next jquery (I have more than 2 languages). When I first thought about it, I had to change the default message values in Editor/Validate.php to tokens.
However, I then thought about updates. So I asked the question here.
Sounds like a good solution. Mine is a little more "primitive". Here is an example with a global validator. These are not global variables. I need to use "use" to be able to use the messages in the validator.
if ($lang === 'de') {
$msg[0] = 'Feld darf nicht leer sein.';
$msg[1] = 'Bitte wählen Sie mindestens eine Installation aus.';
$msg[2] = 'Förderregister: Jede Abteilung kann nur eine Installation haben.';
$msg[3] = 'Vertragsverwaltung: Wegen nutzerübergreifender Laufender Nummer '
. 'kann jede Abteilung nur eine Installation haben.';
} else {
$msg[0] = 'Field may not be empty.';
$msg[1] = 'Please select at least one installation.';
$msg[2] = 'Subsidy Register: Each department can have only one installation.';
$msg[3] = 'Contract Management: Because of cross-user sequential number, '
. 'each department can have only one installation.';
}
....
->validator( function ( $editor, $editorAction, $data ) use ( $msg ) {
if ( $editorAction === Editor::ACTION_CREATE ||
$editorAction === Editor::ACTION_EDIT ) {
foreach ( $data['data'] as $pkey => $values ) {
if ( isset($values['ctr_installation-many-count']) ) {
if ( $values['ctr_installation-many-count'] <= 0 ) {
return $msg[1];
}
if ( (bool)$_POST['is_subsidy_register'] ) {
if ( $values['ctr_installation-many-count'] > 1 ) {
return $msg[2];
}
} else {
if ( $values['ctr_installation-many-count'] > 1 ) {
if ( (bool)$values["numeric_serial"] ) {
return $msg[3];
}
}
}
}
}
return null;
}
} )
For client-side token resolution, you could use postSubmit on the client-side. Spin over the fieldErrors array and replace the status value with the token lookup. If I were to implement token lookup in Editor, then this is exactly what I would be doing internally.
Interesting solution! I am using that, too. But only to capture SQL errors in order to present a meaningful error message to my users:
table
.on( 'postSubmit', function ( e, json, data, action ) {
if (json.error) {
if ( json.error.indexOf('1062 Duplicate entry') >= 0 ) {
json.error = lang === 'de' ?
"Tut uns Leid, aber Sie haben schon eine \n\
zugewiesene Rolle für diese Abteilung!" :
"Sorry, you already have an assigned role for \n\
this department!";
}
if ( json.error.indexOf('1452 Cannot add or update a child row') >= 0 ) {
json.error = lang === 'de' ?
"Keine Dateneingabe erlaubt, nur Auswahl!" :
"Data entry not permitted, only selection!";
}
}
});
Hi Everybody,
Thank you all for your outputs. That was very useful.
However, let me take this a step further. When I said a practical way in my first question, what I meant was re-usability. For example, the Internationalisation plug-ins in datatables does support internatiolisation by design. It is easy to use and maintain.
I hope Editor's back-end messages and database error messages will be redesigned in similar manner in future updates.
It is certainly something I can keep under review. It could be that I check all returned error messages to see if they start editor.error. and if so, run them through i18n().
Answers
https://editor.datatables.net/manual/php/validation
You can set a custom message or use a custom validator. That's it, I guess.
Yup, that's basically it. How else could it be done? Possibly return a token and have that token looked up? Then you'd need to have a list of the tokens and you might as well do the lookup at the server-side?
Allan
I agree, Allan. That wouldn't add much value.
I mostly use custom validators and return English or German from the server depending on the respective user language.
Yes token based solution is what I am looking for. I am using i18next jquery (I have more than 2 languages). When I first thought about it, I had to change the default message values in
Editor/Validate.php
to tokens.However, I then thought about updates. So I asked the question here.
forget to mention that I am doing translation on front-end side.
well.. thanks for sharing ideas. I ended up doing it on server-side like this:
where
$i18n
is an array with the user language messagesSounds like a good solution. Mine is a little more "primitive". Here is an example with a global validator. These are not global variables. I need to use "use" to be able to use the messages in the validator.
For client-side token resolution, you could use
postSubmit
on the client-side. Spin over thefieldErrors
array and replace thestatus
value with the token lookup. If I were to implement token lookup in Editor, then this is exactly what I would be doing internally.Allan
Interesting solution! I am using that, too. But only to capture SQL errors in order to present a meaningful error message to my users:
Hi Everybody,
Thank you all for your outputs. That was very useful.
However, let me take this a step further. When I said
a practical way
in my first question, what I meant was re-usability. For example, the Internationalisation plug-ins in datatables does support internatiolisation by design. It is easy to use and maintain.I hope Editor's back-end messages and database error messages will be redesigned in similar manner in future updates.
It is certainly something I can keep under review. It could be that I check all returned error messages to see if they start
editor.error.
and if so, run them throughi18n()
.Allan