Problem/Motivation

The file slick.html.twig contains aria-label="{{ settings.prevArrow|t }}" as button attributes, but that breaks HTML as the t-filter returns markup and therefore breaks the syntax.

Proposed resolution

Either do not translate the labels or strip tags afterwards.

Issue fork slick-3333772

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

jurgenhaas created an issue. See original summary.

jurgenhaas’s picture

Status: Active » Needs review
gausarts’s picture

Thank you.

Mind providing before and after with HTML markups for docs purposes?

Honestly, I never thought string translation would output any HTML :)

If HTML were added by Twig purposedly or by design, I think it was a bad move, and would cause many troubles anywhere else. The fix should be upstream, not at module level, IMHO.

However, I am fine to include your fix.

It was just an unfortunate HTML addition what I was concerned about.

Almost similar, just an FYI, relevant striptags were done upstream to fix the same translation issue:
#3075838: Configuration translation disallowed HTML

jurgenhaas’s picture

Here is the HTML before the fix:

<nav role="navigation" class="slick__arrow">
    <button type="button" data-role="none" class="slick-prev visually-hidden" aria-label="<button type=" button"="" tabindex="0" role="button">Previous</button>" tabindex="0"&gt;<button type="button" data-role="none" class="slick-prev visually-hidden" aria-label="Previous" tabindex="0" role="button">Previous</button>
    <button type="button" data-role="none" class="slick-next visually-hidden" aria-label="<button type=" button"="" tabindex="0" role="button">Next</button>" tabindex="0"&gt;<button type="button" data-role="none" class="slick-next visually-hidden" aria-label="Next" tabindex="0" role="button">Next</button>
</nav>

And that's the HTML after the fix:

<nav role="navigation" class="slick__arrow">
    <button type="button" data-role="none" class="slick-prev visually-hidden" aria-label="Previous" tabindex="0"></button><button type="button" data-role="none" class="slick-prev visually-hidden" aria-label="Previous" tabindex="0" role="button">Previous</button>
    <button type="button" data-role="none" class="slick-next visually-hidden" aria-label="Next" tabindex="0"></button><button type="button" data-role="none" class="slick-next visually-hidden" aria-label="Next" tabindex="0" role="button">Next</button>
</nav>

TBH, not sure if this can even be fixed upstream because the t-function, which is used here, returns TranslatableMarkup. And outside of an HTML attribute, that's probably exactly what you want. So stripping tags upstream would break other stuff.

gausarts’s picture

Got it, thanks.

Please allow delay to get back to it.

  • gausarts committed 51565d0c on 8.x-2.x authored by jurgenhaas
    Issue #3333772 by jurgenhaas: Translation of aria labels breaks HTML
    
gausarts’s picture

Status: Needs review » Fixed

Committed. Thank you for contribution and patience.

Status: Fixed » Closed (fixed)

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