Currently, error messages generated in SamlController can't be modified or translated.

For example, site admins can't modify the following message:

No existing user account matches the SAML ID provided. This authentication service is not configured to create new accounts.

If that text was translatable, it could also be modified via $settings['locale_custom_strings_*'].

Issue fork samlauth-3262269

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jeffam created an issue. See original summary.

jeffam’s picture

Status: Active » Needs review
a-fro’s picture

Status: Needs review » Reviewed & tested by the community

roderik made their first commit to this issue’s fork.

roderik’s picture

Status: Reviewed & tested by the community » Needs review

Drupal development best practices say we should not translate variable strings. (Except for the '$which' case which I'm handwaving away in a comment...)

Also, the logger should get the untranslated message. (The standard dblog saves the untranslated message plus replacements separately, and translates them on output. We don't want the translation system to retranslate the already translated message.)

How does this work for you? ^ (UserVisibleException having the translated message, but having the untranslated message plus replacements available for e.g. logging.

jeffam’s picture

Thanks for taking a look at this.

Honestly, I'm fine with any solution that allows me to override the error message displayed to the user.

Looking through core, though, I think that the original commit is fine (except for the translation of the string with $while in it).

There are a bunch of examples in core of messages being translated, like this one from the block_content module:

$this->messenger()->addError($this->t('The block could not be saved.'));

Note also in that commit that the logger message arguments aren't translated, just the arguments to addError().

roderik’s picture

OK, if this works then I'll commit it and do a new release.

There are a bunch of examples in core of messages being translated, like this one from the block_content module:

Oh, absolutely. Messages should be translated. (At least the "User facing" exceptions.) This was either an oversight or laziness when I committed #3053187: Improve error messages when account doesn't map. Thank you for contributing this.

But we shouldn't pass variable messages, like Destination URL query parameter must not be external: $destination. (A string containing the $while is still 'bad', but not as bad because it has only ~3 permutations. I'll probably get rid of it completely in 4.x, along with the rest of that code block.)

Note also in that commit that the logger message arguments aren't translated, just the arguments to addError().

You're right. I mean the logger should get the template message plus arguments separately, so e.g. Destination URL query parameter must not be external: @destination, with any argument not substituted yet but passed in separately.

  • roderik committed 9bf0a5d on 8.x-3.x authored by jeffam
    Issue #3262269 by jeffam, roderik, a-fro: Translate error messages
    
roderik’s picture

Status: Needs review » Fixed
jeffam’s picture

This looks great, and I finally get the issue with that '$destination' error message that I wasn't thinking about.

I appreciate the quick release and your work on this module. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.