Now that at least some of the custom error messages for parameter validation attributes support custom error messages - see #3745, it should be possible to support localization of these error messages - currently, only literal strings are supported.
Without this ability, localized scripts are effectively prevented from using such validation attributes.
What currently works:
function foo {
param(
[ValidatePattern('o', ErrorMessage = 'Must have an "o".')]
$bar
)
$bar
}
foo -bar baz
This yields:
foo : Cannot validate argument on parameter 'bar'. Must have an "o".
What support for localization might look like (not sure about feasibility; solely based on noticing that some attributes accept script blocks):
$stringTable = DATA {
@{
msg = 'Must have an "o".'
}
}
function foo {
param(
[ValidatePattern('o', ErrorMessage = { $stringTable.msg })]
$bar
)
$bar
}
foo -bar baz
Environment data
PowerShell Core v6.0.0-beta (v6.0.0-beta.1)
Now that at least some of the custom error messages for parameter validation attributes support custom error messages - see #3745, it should be possible to support localization of these error messages - currently, only literal strings are supported.
Without this ability, localized scripts are effectively prevented from using such validation attributes.
What currently works:
This yields:
What support for localization might look like (not sure about feasibility; solely based on noticing that some attributes accept script blocks):
Environment data