Currently the value inside "access_denied_message" configuration variable is not translatable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cristiroma created an issue. See original summary.

cristiroma’s picture

Status: Active » Needs review
Related issues: +#1719342: Enable message type selection
FileSize
1.35 KB

Attaching a patch to fix the problem using StringTranslationTrait as recommended here: https://www.drupal.org/node/322729.

Edit: I'm not sure this is 100% correct, as the output of Xss::filterAdmin($message) might end-up different from $message and the system could not pick-up the actual string to match against translations. On the other hand I was wondering couldn't the string be sanitised during saving instead during display?

cristiroma’s picture

Attaching a patch to sanitise the input also during saving, this way the string is fixed then translated.

mr.baileys’s picture

Good catch.

Attaching a patch to sanitise the input also during saving

Filtering should almost always be done on output, see https://www.drupal.org/docs/7/security/writing-secure-code-0/why-does-dr...

The documentation you linked to seems to be for Drupal 7. In Drupal 8, configuration is translatable, and the 'access denied'-string is part of configuration, so should be translated using the "configuration translation" framework/module, rather than running the string through t().

Since the module adds its configuration fieldset to the system information form, hook_config_translation_info_alter() needs to be used to include the translatable settings when translating system.site_information_settings. After applying the patch attached here and enabling the config translation module, you can translate the 'access denied' text via /admin/config/system/site-information/translate.

nedjo’s picture

Status: Needs review » Needs work

@mr.baileys

Nice work. A couple of suggestions.

  1. +++ b/config/schema/r4032login.schema.yml
    @@ -23,3 +23,6 @@ r4032login.settings:
    +     type: string
    +     label: 'Language code'
    

    Needs one more space indentation.

  2. +++ b/r4032login.module
    @@ -150,3 +150,10 @@ function r4032login_theme() {
    + * Implements hook_config_translation_info_alter().
    ...
    +  $info['system.site_information_settings']['names'][] = 'r4032login.settings';
    


    From the the hook_config_translation_info_alter() documentation, it looks like best practice here might be to pull the specific setting into a new configuration file, r4032login.site.setting.

nedjo’s picture

From the the hook_config_translation_info_alter() documentation, it looks like best practice here might be to pull the specific setting into a new configuration file, r4032login.site.setting.

Cancel that, I was overlooking the fact that all this module's configuration is added to that form.

  • Nixou committed be704c8 on 8.x-1.x authored by mr.baileys
    Issue #2816587 by mr.baileys: The 'access denied' string presented to...
Nixou’s picture

Status: Needs work » Fixed

Committed, thanks !

Status: Fixed » Closed (fixed)

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