@@ -9,12 +9,11 @@ namespace LORIS\my_preferences;
99 */
1010class My_Preferences extends \NDB_Form
1111{
12+ // Use gettext for error messages
1213 private const PASSWORD_ERROR_IS_EMAIL = 'Your password cannot be your email. ' ;
13- private const PASSWORD_ERROR_IS_USER = 'Your password cannot be ' .
14- 'your user name. ' ;
14+ private const PASSWORD_ERROR_IS_USER = 'Your password cannot be your user name. ' ;
1515 private const PASSWORD_ERROR_NO_MATCH = 'The passwords do not match. ' ;
16- private const PASSWORD_ERROR_NO_CHANGE = 'New and old passwords are ' .
17- 'identical: please choose another one ' ;
16+ private const PASSWORD_ERROR_NO_CHANGE = 'New and old passwords are identical: please choose another one ' ;
1817
1918 /**
2019 * Computes the initial values this page will be filled with.
@@ -223,21 +222,19 @@ class My_Preferences extends \NDB_Form
223222 //get notification details
224223 $ notifier_list = \NDB_Notifier::getNotificationModuleServices ();
225224 $ notifier_services = \NDB_Notifier::getNotificationServices ();
226- //------------------------------------------------------------
227225
228226 // user name
229- $ this ->addScoreColumn ('UserID ' , ' User name ' );
227+ $ this ->addScoreColumn ('UserID ' , dgettext ( ' my_preferences ' , ' User name ') );
230228
231229 // full name
232230 // The supplied pattern is:
233231 // - must have at least one non-whitespace characters (i.e. required)
234232 // - once leading and trailing spaces are stripped, the field should
235233 // not exceed 120 chars
236- $ firstNameInvalidMsg = "First name is required and "
237- . "should not exceed 120 characters " ;
234+ $ firstNameInvalidMsg = dgettext ('my_preferences ' , "First name is required and should not exceed 120 characters " );
238235 $ this ->addBasicText (
239236 'First_name ' ,
240- ' First name ' ,
237+ dgettext ( ' my_preferences ' , ' First name ') ,
241238 [],
242239 [
243240 'oninvalid ' => "this.setCustomValidity(' $ firstNameInvalidMsg') " ,
@@ -250,11 +247,10 @@ class My_Preferences extends \NDB_Form
250247 // - must have at least one non-whitespace characters (i.e. required)
251248 // - once leading and trailing spaces are stripped, the field should
252249 // not exceed 120 chars
253- $ lastNameInvalidMsg = "Last name is required and "
254- . "should not exceed 120 characters " ;
250+ $ lastNameInvalidMsg = dgettext ('my_preferences ' , "Last name is required and should not exceed 120 characters " );
255251 $ this ->addBasicText (
256252 'Last_name ' ,
257- ' Last name ' ,
253+ dgettext ( ' my_preferences ' , ' Last name ') ,
258254 [],
259255 [
260256 'oninvalid ' => "this.setCustomValidity(' $ lastNameInvalidMsg') " ,
@@ -267,36 +263,36 @@ class My_Preferences extends \NDB_Form
267263 // email address
268264 $ this ->addBasicText (
269265 'Email ' ,
270- ' Email address ' ,
266+ dgettext ( ' my_preferences ' , ' Email address ') ,
271267 [],
272268 [
273- 'oninvalid ' => "this.setCustomValidity('Email address is required') " ,
269+ 'oninvalid ' => "this.setCustomValidity(' " . dgettext ( ' my_preferences ' , ' Email address is required ' ) . " ') " ,
274270 'onchange ' => "this.setCustomValidity('') " ,
275271 ]
276272 );
277273
278274 // email address rules
279- $ this ->addRule ('Email ' , ' Email address is required ' , 'required ' );
275+ $ this ->addRule ('Email ' , dgettext ( ' my_preferences ' , ' Email address is required ') , 'required ' );
280276 $ this ->addRule (
281277 'Email ' ,
282- ' Your email address must be less than 255 characters long ' ,
278+ dgettext ( ' my_preferences ' , ' Your email address must be less than 255 characters long ') ,
283279 'maxlength ' ,
284280 "255 "
285281 );
286282
287283 // password
288- $ this ->form ->addElement ('password ' , 'Password_hash ' , ' New Password ' );
289- $ this ->form ->addElement ('password ' , '__Confirm ' , ' Confirm Password ' );
284+ $ this ->form ->addElement ('password ' , 'Password_hash ' , dgettext ( ' my_preferences ' , ' New Password ') );
285+ $ this ->form ->addElement ('password ' , '__Confirm ' , dgettext ( ' my_preferences ' , ' Confirm Password ') );
290286
291287 // language preference
292288 $ languages = \Utility::getLanguageList ();
293- $ this ->addSelect ('language_preference ' , ' Language preference ' , $ languages );
289+ $ this ->addSelect ('language_preference ' , dgettext ( ' my_preferences ' , ' Language preference ') , $ languages );
294290
295291 // Notification headers
296292 $ nGroup = [];
297- $ nGroup [] = $ this ->createLabel ("Module " );
298- $ nGroup [] = $ this ->createLabel ("Operation " );
299- $ nGroup [] = $ this ->createLabel ("Description " );
293+ $ nGroup [] = $ this ->createLabel (dgettext ( ' my_preferences ' , "Module " ) );
294+ $ nGroup [] = $ this ->createLabel (dgettext ( ' my_preferences ' , "Operation " ) );
295+ $ nGroup [] = $ this ->createLabel (dgettext ( ' my_preferences ' , "Description " ) );
300296
301297 foreach ($ notifier_services as $ serv ) {
302298 $ nGroup [] = $ this ->createLabel ($ serv );
@@ -337,7 +333,7 @@ class My_Preferences extends \NDB_Form
337333 );
338334 } else {
339335 $ nGroup [] = $ this ->createLabel (
340- "N/A "
336+ dgettext ( ' my_preferences ' , "N/A " )
341337 );
342338 }
343339
@@ -397,18 +393,18 @@ class My_Preferences extends \NDB_Form
397393 $ plaintext = $ values ['Password_hash ' ];
398394
399395 if ($ values ['Email ' ] === $ plaintext ) {
400- $ errors ['Password_Group ' ] = self ::PASSWORD_ERROR_IS_EMAIL ;
396+ $ errors ['Password_Group ' ] = dgettext ( ' my_preferences ' , self ::PASSWORD_ERROR_IS_EMAIL ) ;
401397 }
402398
403399 // Make sure the user is not using their username as their password.
404400 if ($ this ->identifier === $ plaintext ) {
405- $ errors ['Password_Group ' ] = self ::PASSWORD_ERROR_IS_USER ;
401+ $ errors ['Password_Group ' ] = dgettext ( ' my_preferences ' , self ::PASSWORD_ERROR_IS_USER ) ;
406402 }
407403
408404 // Ensure that the password and confirm password fields match.
409405 // TODO This validation should be done on the front-end instead.
410406 if ($ values ['Password_hash ' ] !== $ values ['__Confirm ' ]) {
411- $ errors ['Password_Group ' ] = self ::PASSWORD_ERROR_NO_MATCH ;
407+ $ errors ['Password_Group ' ] = dgettext ( ' my_preferences ' , self ::PASSWORD_ERROR_NO_MATCH ) ;
412408 return $ errors ;
413409 }
414410
@@ -425,17 +421,17 @@ class My_Preferences extends \NDB_Form
425421 $ decoded
426422 )
427423 ) {
428- $ errors ['Password_Group ' ] = self ::PASSWORD_ERROR_NO_CHANGE ;
424+ $ errors ['Password_Group ' ] = dgettext ( ' my_preferences ' , self ::PASSWORD_ERROR_NO_CHANGE ) ;
429425 }
430426 } catch (\InvalidArgumentException $ e ) {
431- $ errors ['Password_Group ' ] = $ e ->getMessage ();
427+ $ errors ['Password_Group ' ] = dgettext ( ' my_preferences ' , $ e ->getMessage () );
432428 }
433429 }
434430
435431 // Validate email
436432 $ emailError = $ this ->_getEmailError ($ DB , $ values ['Email ' ]);
437433 if (!is_null ($ emailError )) {
438- $ errors ['Email ' ] = $ emailError ;
434+ $ errors ['Email ' ] = dgettext ( ' my_preferences ' , $ emailError) ;
439435 }
440436
441437 return $ errors ;
@@ -456,7 +452,7 @@ class My_Preferences extends \NDB_Form
456452 $ email = filter_var ($ email , FILTER_SANITIZE_EMAIL );
457453 if (!filter_var ($ email , FILTER_VALIDATE_EMAIL )) {
458454 // If email not syntactically valid
459- return "Invalid email address " ;
455+ return dgettext ( ' my_preferences ' , "Invalid email address " ) ;
460456 }
461457
462458 // check email address' uniqueness
@@ -470,7 +466,7 @@ class My_Preferences extends \NDB_Form
470466
471467 // Email already exists in database
472468 if ($ result > 0 ) {
473- return ' The email address already exists ' ;
469+ return dgettext ( ' my_preferences ' , ' The email address already exists ') ;
474470 }
475471
476472 return null ;
0 commit comments