core icon indicating copy to clipboard operation
core copied to clipboard

ngx-translate doesn't translate ng-container element

Open yuezhizizhang opened this issue 5 years ago • 3 comments

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:

yuezhizizhang avatar Jul 25 '18 02:07 yuezhizizhang

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

all43 avatar Sep 01 '18 15:09 all43

@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.

longgt avatar Jan 14 '19 10:01 longgt

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.

JBBianchi avatar Jul 23 '21 08:07 JBBianchi