question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Entire HTML template ignored when key with `{{...}}` used

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is this a regression?

No

Current behavior

When I was running transloco-keys-manager extract - I found that some of my .html files were being skipped and keys from those html files were not being extracted into my en.json file.

I tried a bunch of variations and finally found:

Scenario 1: Use transloco with a {{ in the key Result: 0 keys found … expected 2 keys to be found

{{ '{{count}} items' | transloco:{ count: item.usageCount } }}
{{ 'key2' | transloco }}

Scenario 2: Use transloco with a { in the key Result: 2 keys found

{{ '{count} items' | transloco:{ count: 0 } }}
{{ 'key2' | transloco }}

Scenario 3: Use transloco with {{ in key + without a dict as the argument Result: 2 keys found

{{ '{{count}} items' | transloco:1 }}
{{ 'key2' | transloco }}

Scenario 4: Use transloco with {{ in key + add as attribute in a tag Result: 2 keys found

<a [title]="'{{count}} items' | transloco:{ count: 0 }"></a>
{{ 'key2' | transloco }}

Expected behavior

All the keys should have been found and added to my en.json file

I was not able to create an easy minimal example, but I simply created a folder transloco_testing and added a single file testing.html

$ tree app/transloco_testing/
app/transloco_testing/
└── testing.html

0 directories, 1 file

$ cat app/transloco_testing/testing.html
{{ '{{count}} items' | transloco:{ count: item.usageCount } }}
{{ 'key2' | transloco }}

And then ran:

$ ./node_modules/.bin/transloco-keys-manager extract --input app/transloco_testing
Starting Translation File Build 👷🏗

✔ Extracting Template and Component Keys 🗝
ℹ 0 keys were found in 1 file.

              🌵 Done! 🌵

Please provide a link to a minimal reproduction of the bug

Described above

Transloco Config

No response

Debug Logs

No response

Please provide the environment you discovered this bug in

Transloco: 4.0.0
Transloco Keys Manager: 3.3.5
Angular: 11.2.14
Node: 16.13.2
Package Manager: npm 8.1.2
OS: Windows 10 + Ubuntu 18.04 WSL2

Additional context

No response

I would like to make a pull request for this bug

No

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AbdealiLoKocommented, Apr 12, 2022

@shaharkazaz I tried looking into it briefly - and I found that the issue was from the angular parseTemplate: https://github.com/ngneat/transloco-keys-manager/blob/v3.4.1/src/keys-builder/template/utils.ts#L85

So, first issue I feel is that when parseTemplate has an error today - we are not showing that to the user currently and silently skipping it.

The error coming in was that the {{ was not escaped correctly. I checked that in angular 12 - the above syntax would give you a SyntaxError when doing a ng build But in angular 13 - it works fine Looks like we would need to upgrade the angular compiler version to 13 - and I wasn’t sure if that was something we should be doing or not

0reactions
shaharkazazcommented, Apr 17, 2022

@AbdealiJK Nice summary 🔥

So, first issue I feel is that when parseTemplate has an error today - we are not showing that to the user currently and silently skipping it.

I think you are correct and we need to inform you that a parsing error has occurred within a certain file and log it, but it should continue with the processing.

Looks like we would need to upgrade the angular compiler version to 13 …

I don’t have any objection to upgrading the compiler to v13. We can release it as a new major version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Using Go Templates, Don't Neglect the “missingkey ...
In this example, we're using HTML as our template, which has a single token to replace, “name”. We pass some JSON data to...
Read more >
Ignore sections of a template if there is no value in Go
When a form is submitted it loads a results.html that is identical to the index.html except some Go templating to print the results...
Read more >
<tbody>: The Table Body element - HTML - MDN Web Docs
The HTML element encapsulates a set of table rows ( elements), indicating that they comprise the body of the table ( ).
Read more >
Template Designer Documentation - Jinja
For example, {{ name|striptags|title }} will remove all HTML Tags from variable name and title-case the output ( title(striptags(name)) ). Filters that accept ......
Read more >
Error Boundaries - React
In the past, JavaScript errors inside components used to corrupt React's internal ... A JavaScript error in a part of the UI shouldn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found