Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

localize-translate throws 'undefined' error when string contains braces #38569

Closed
ArtemAvramenko opened this issue Aug 25, 2020 · 7 comments
Closed

Comments

@ArtemAvramenko
Copy link

馃悶 bug report

Affected Package

The issue is caused by package @angular/localize^10.1.0-next.7

Description

In ts code I use i18n:
$localize`hello {world}`

then I extract xlf and translate it:

<trans-unit id="1122334455667788999" datatype="html">
  <source>hello {world}</source>
  <context-group purpose="location">
    <context context-type="sourcefile">myapp.js</context>
    <context context-type="linenumber">1234</context>
  </context-group>
<target xml:lang="es">hola {mundo}</target>
</trans-unit>

then I run localize-translate and get undefined error:

npx localize-translate -r scripts -s myapp.js -t strings.es.xlf -o es

馃敟 Exception or Error

undefined

馃實 Your Environment

Angular Version:

10.1.0-next.7
@ngbot ngbot bot added this to the needsTriage milestone Aug 25, 2020
@petebacondarwin
Copy link
Member

Yeah - so the {world} string in your message is not valid, since such curly braced blocks will be interpreted as ICU expressions. We should provide better error messaging...

@ArtemAvramenko
Copy link
Author

How to escape braces so end-users can see them on UI?

@petebacondarwin
Copy link
Member

The approach in templates is to use interpolation: something like:

<div i18n>hello {{ '{' }}world}</div>

In application code, I think you could do something similar like:

$localize`hello ${'{'}world}`

@petebacondarwin
Copy link
Member

I just tried this with the latest versions of Angular and Angular-CLI (10.1.0-rc.0). This is the error I get:

/Users/pete/dev/angular/tmp/issue38569/node_modules/@angular/localize/src/tools/src/translate/translation_files/translation_loader.js:93
                finally { if (e_1) throw e_1.error; }
                                   ^
Error: Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)
Error: Invalid ICU message. Missing '}'.
error Command failed with exit code 1.

I get a similar error if I use the CLI to do the localization:

ng build --localize
Error: Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)
Error: Invalid ICU message. Missing '}'.

This seems like a better error message than the undefined that you report above. Can you check to see if this is still the case for you?

This leads us onto the #38377 issue, which is about making this error message more helpful.

@ArtemAvramenko
Copy link
Author

I checked 10.1.0-rc.0 - the error is more informative now. Thanks

@petebacondarwin
Copy link
Member

Great. I am working on improving the error further.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants