Skip to content

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

Closed

Description

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)

Activity

  1. added
    WG-Enginecore PowerShell engine, interpreter, and runtime
    Issue-Enhancementthe issue is more of a feature request than a bug
    on May 12, 2017
  2. iSazonov commented on May 12, 2017

    @iSazonov
    Collaborator

    Related #2728 (comment)

    if we go that route, we need localization support similar to HelpMessageBaseName and HelpMessageResourceId in ParameterAttribute

  3. mmsaffari commented on Jan 21, 2020

    @mmsaffari

    Are HelpMessageBaseName and HelpMessageResourceId currently working?

  4. wbpluto commented on Apr 18, 2020

    @wbpluto

    Still waiting for this. Come on, Microsoft, your're a global company.

  5. iSazonov commented on Apr 20, 2020

    @iSazonov
    Collaborator

    Junwei Huang (@wbpluto) It is an open source project so you can pull PR.

  6. mklement0 commented on Apr 20, 2020

    @mklement0
    Author
  7. iSazonov commented on Apr 21, 2020

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) I only point that everybody can contribute and do not wait.
    For the issue a solution was mentioned in #3765 (comment)

  8. mklement0 commented on Apr 21, 2020

    @mklement0
    ContributorAuthor

    Thanks, Ilya (@iSazonov) - coming back here I'd forgotten that this issue is about enabling localization of a user-supplied message, not about localizing PowerShell's own messages (which is what #666 is about).

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions