← Back to team overview

anewt-developers team mailing list archive

Text/error strings / internationalization support

 

Anewt developers,

There are quite some instances in anewt where you would want to display an error message, particularly in form controls during validation. The current solution is to use either a hard coded error string, or no message at all. Both are not really desirable.

Maybe we could do something with internationalization? I see there is a very basic i18n module, but I have no practical knowledge of how to use i18n/gettext.

I suggest something like the following:

class SomethingWhichValidates {
	function __construct() {
		$this->seed(array(
			...,
			'error_message' => _('My error'),
		));
	}
	...
	function is_valid() {
		...
		if (!$valid) {
			$this->error = $this->error_message;
		}
		return $valid;
	}
}

That way you can have a default internationalized error message, and it's also user overridable.

I'm not saying we should use this for our current validators, just for some form controls which also have some internal validation (like AnewtFormControlText to check if there is a newline in there somewhere).

The basic problem is how to store/retrieve all the text strings. I have no knowledge of i18n/gettext, so I don't know how that works. Also, "_('My error')" could also be something like "ANEWT_TEXT_SOMETHING_ERROR_MESSAGE" or "_('ERROR_MESSAGE')" or something, I don't know.

Bonus points if the error strings are user configurable (e.g., supply a filename with the translations). Even more bonus points if he only has to supply the overridden strings.

-- Sander



Follow ups