Core: Spaces in innerText of the directive make MissingTranslationHandler crash (regression)

Created on 1 Aug 2018  路  7Comments  路  Source: ngx-translate/core

Current behavior

I've found a regression between v9.1.1 and 10.02.

I'm using a custom MissingTranslationHandler likes this:

export class CustomMissingTranslationHandler implements MissingTranslationHandler {
  handle(params: MissingTranslationHandlerParams) {
    return `MISSING:${params.key}`;
  }
}

In v9.1.1, such syntax would be translated anyway (space added before 'foo'):
<p><span translate> foo</span>

==> stackblitz of v9.1.1

It's not the case anymore in v10.0.2. Detailed behavior here: stackblitz of v10.0.2

Expected behavior

I suppose the behavior should be the same as v 9.1.1: the innerText should be trimmed and then translated. In my point of view, it's annoying. Of course we should format our code, but it's easy to miss a space while using this kind of syntax:

<div [class.required]="true" translate>
    destinataire
</div>

How do you think that we should fix this?

Don't know yet, didn't dig into the code. Will do !

Minimal reproduction of the problem with instructions

Add a space before any innerText to be translated with the 'translate' directive. Details in provided stackblitz above.

Environment

ngx-translate version: 10.0.2
Angular version: 6.1.0

Browser:

  • [x] Chrome (desktop) version 67
  • [ ] Chrome (Android) version XX
  • [ ] Chrome (iOS) version XX
  • [x] Firefox version 60.0.2
  • [ ] Safari (desktop) version XX
  • [ ] Safari (iOS) version XX
  • [ ] IE version XX
  • [ ] Edge version XX

Most helpful comment

Is this gonna bee addressed at some point? It is annoying having to put the tags in a liner...

All 7 comments

I have exactly the same problem.

If i use this.

<p translate>label</p>

it works, but if i do this

<p translate>
  label
</p>

it has a strange behavior. It translate the text, but the missing translation trigger is fired.

I also have the same problem.
<p translate>
label
</p>
it works in the first in a component, but if then i use the translate.use to change the language(don't change the component), it often don't work.

I have the same problem. For all those keywords that are used like

when they get a line break before or after the key it is bugged: it doesn't change the translation when changing the language. It only translates correctly on reload.
It works when using Tabs for Indentation instead of Spaces but can't do that for the whole project.

I have similar problem as mentioned in above comment

Related bug:

383

887

Is this gonna bee addressed at some point? It is annoying having to put the tags in a liner...

I have exactly the same problem.

If i use this.

<p translate>label</p>

it works, but if i do this

<p translate>
  label
</p>

it has a strange behavior. It translate the text, but the missing translation trigger is fired.

Thank you man.. Give this man a medal!

We have the same problem in our project. We use the directive on many places in formatted untrimmed code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IterationCorp picture IterationCorp  路  3Comments

briancullinan picture briancullinan  路  3Comments

dankerk picture dankerk  路  3Comments

jellene4eva picture jellene4eva  路  3Comments

webprofusion-chrisc picture webprofusion-chrisc  路  4Comments