Skip to content

Localize error messages

Created by: dregad

While in the process of adapting one of my apps to make use of the new localized help in GetOpt 3.1, I noticed that GetOpt has several user-facing error messages which have not been localized. I would expect these strings to be translated as well, as they are part of the app's front-end.

Sample code, defining an Option with required or validated arguments:

$opt = new \GetOpt\GetOpt([
	\GetOpt\Option::create('t', null, \GetOpt\GetOpt::REQUIRED_ARGUMENT)
		->setValidation(function($arg) { return is_numeric($arg); })
]);
$opt->setHelpLang('fr');
try {
	$opt->process();
} catch (\GetOpt\ArgumentException $e) {
	echo $e->getMessage() . PHP_EOL;
}

Output, should be localized:

$ php test.php -z
Option 'z' is unknown

$ php test.php -t 
Option 't' must have a value

$ php test.php -t x
Option 't' has an invalid value