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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text missing for empty translation target #15754

Closed
moritz-h opened this issue Apr 4, 2017 · 13 comments
Closed

Text missing for empty translation target #15754

moritz-h opened this issue Apr 4, 2017 · 13 comments

Comments

@moritz-h
Copy link

moritz-h commented Apr 4, 2017

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

creating a messages.xlf using Angular CLI: ng xi18n
As i don't need to translate English to English I use the generated file to build the English version
ng serve --aot --locale en --i18n-file src/messages.xlf
=> All strings are missing
(i think this comes from empty <target /> in the xfl file)
Same for all other languages. Documentation suggests to copy the messages.xlf to /locale/messages.??.xlf. If I now build the localized version with a incomplete translation, all not translated strings are missing.

Expected behavior

I would expect that missing translations show the original string instead of nothing.

Minimal reproduction of the problem with instructions

see Current behavior

What is the motivation / use case for changing the behavior?

Keeping all translation files up to date in time is a complicated workflow and then a not translated string is better than a missing string.

Please tell us about your environment:

  • Angular version: 4.0.1
  • Browser: Firefox/Chrome
  • Language: N/A

  • Node (for AoT issues): v6.10.1

@vicb
Copy link
Contributor

vicb commented Apr 4, 2017

If you specify an empty target... the target message will be empty - I think this is working as expected.

However If the message is not part of the translation bundle (your xliff file) then the original message will be used.

If this makes sense please close the issue.

@moritz-h
Copy link
Author

moritz-h commented Apr 4, 2017

@vicb
Yes it makes sense that empty target really means empty.

But then I think the bug is then that the xi18n tool generates the empty tags. The meaning of this is that angular by default translates everything with an empty string. I don't read the XLIFF specification, but according to Wikipedia the <target> is not mandatory: https://en.wikipedia.org/wiki/XLIFF

If Angular would generate the xlf file without target, you could copy it for each language as suggested in the documentation without problems of missing translations. For this Angular could somehow interpret a missing <target> the same way as if the whole <trans-unit> is missing. (currently a missing target crashes)

Drawback would be that users have to know that they must add the target element and also if you edit the file manual the extra typing.
But otherwise with the current behaviour, you must manual delete alls trans-units if you don't translate all of them at one time.

If you want to keep the current behavior, it would at least be helpful to write this in the documentation.

@ocombe
Copy link
Contributor

ocombe commented Apr 12, 2017

This is not really a bug, but more like a feature request.
You're not really supposed to generate the translations files manually, you will most likely use an external tool to generate translations files.
I see 3 different solutions to your problem:

  • keep the current behavior but update the docs
  • copy the source content into the target when generating the messages file
  • don't create the empty target elements

I don't think 3/ is the good solution. I'd go with either 1/ or 2/

@moritz-h
Copy link
Author

2/ :+1:

I still think not translating is better than translating with empty string (what 1/ would do). Just copy source to target would be fine.
I started using Weblate as tool. To define one file as the source to use for all translations, Weblate currently reads the target of this file. So for this case also 2/ would be nice. (Perhaps this is only Weblate related and no general argument.)
Do you know how this is handled by other tools?

I tried to get more information how this general is handled. I read through the XLIFF spec, but I don't find more information than the general info that target is optional. Also I searched for other xlf files on github and found projects for all cases 1/ 2/ 3/, so I think there is no general solution.

@nlgi
Copy link

nlgi commented Apr 25, 2017

Same "bug" for me.

I have an application in French, so i18n source is in French. I'm using tools like kendo, with source in english, so I need a messages.fr.xlf file to translate its source in french.
I have to duplicate source data in target for my labels (2/), it's very long.

I think not translating is better than translating with empty string, but if this is not a feature request, is there any tool to complete all empty target automatically by the source element?

Many thanks,

@ocombe
Copy link
Contributor

ocombe commented Apr 25, 2017

@martinroob do you think that you can add this to your ngx-i18nsupport tool?

@martinroob
Copy link

This is exactly what ngx-i18nsupport does by default.
It copies the source to the target element if target is empty.
So there is nothing to add here.

@moritz-h
Copy link
Author

moritz-h commented May 4, 2017

Thanks for mentioning @martinroob's tool. Works perfectly for me with this.

But I still think the current Angular behaviour is strange. (Perhaps the existance of a support tool is also a big argument for this 😄 )
Are there any plans in merging the support tool to Angular oder AngularCLI directly?

@sunild
Copy link

sunild commented Jun 20, 2017

I think I've found an even easier solution, based on the comment from @vicb:

If you specify an empty target... the target message will be empty - I think this is working as expected.
However If the message is not part of the translation bundle (your xliff file) then the original message will be used.

I deleted all the lines from the messages.en.xlf file and built the app for the English locale, since all the translation units were missing, it used the original English strings.

Seems a bit weird to bother with passing in the i18n arguments at all when building for English, but at least it keeps the build process the same for all languages.

@redhat-raptor
Copy link

Hello, faced the same problem. Like @sunild said, removing the source from xlf file solves the problem. However I was wondering if it would be great to set a flag while generating the xlf file? This way we wouldn't need to manually remove the entries.

@vicb
Copy link
Contributor

vicb commented Jul 7, 2017

Ok, got the problem.
👍 to stop generating the <target/>

@ottawaman
Copy link

ottawaman commented Sep 20, 2017

Thank you for working on this tool but please consider the following:

Is there an optional parameter which can be passed to the extraction tool, to still produce the empty <target/> nodes in the messages.xlf file?

A change such as not generating <target/> node in the produced .xlf file (which is a structural change) should have been considered more carefully and in my opinion should have been implemented as an option and not a default behavior (or the only available behavior) to keep backward compatibility with the previous versions of the file structure, produced by the previous versions of the text extraction tool.

Since I upgraded to the latest version of Angular (4.4), my Locale AOT builds are broken and I figured out that is because now the Angular extraction tool, does not generate the empty tag in the messages.xlf file anymore. I had a custom script to add customized localized strings to the messages.xlf file based on the existence of <target/>in this file. My custom script would take the text from <source>, add a localized prefix to the text and populate the <target> nodes with these fake translations, so I could create my localized bundles.
This allowed me to use fake translations and have localized builds while I was waiting for my real translated .xlf files from the translators.
Since this latest unnecessary change in the extraction tool, this workflow and my AOT builds are all broken.

@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 Sep 12, 2019
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

8 participants