Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support localization of custom error messages for parameter validation attributes #3765

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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)
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.