ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.53k stars 578 forks source link

ngx-translate doesn't translate ng-container element #903

Open yuezhizizhang opened 6 years ago

yuezhizizhang commented 6 years ago

Current behavior

I have an element: <ng-container [translate]="'name'">Name

ngx-translate doesn't translate it. But If I change the element to span, it works.

Expected behavior

ngx-translate should be able to translate ng-container element.

How do you think that we should fix this?

Minimal reproduction of the problem with instructions

Environment


ngx-translate version: X.Y.Z
Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

For Tooling issues:
- Node version: XX  
- Platform:  

Others:

all43 commented 6 years ago

Same for all custom elements, don't know is it ngx-translate or angular issue. I'm using translate pipe instead.

longgt commented 5 years ago

@yuezhizizhang Following the link below, https://netbasal.com/getting-to-know-the-ng-container-directive-in-angular-a97b7a33c8ea

<ng-container> is a logical container that can be used to group nodes but is not rendered in the DOM tree as a node.
<ng-container> is rendered as an HTML comment.

so this is expected result.

JBBianchi commented 3 years ago

so this is expected result.

I'm not 100% sure. It's not because ng-container itself is not rendered and considerated a comment that a text node inside of it should be ignored. In other words:

<ng-container>something, whaterver it is, text or nodes</ng-container>

produces

something, whaterver it is, text or nodes
<!---->

A text node is still a node, a leaf to be more precise, it doesnt "disappear" because it's wrapped in a ng-container. The ng-container just allows to avoid to output a new node, like a span, that would just make the DOM heavier.