angular icon indicating copy to clipboard operation
angular copied to clipboard

Support UTF in Angular expressions

Open vicb opened this issue 9 years ago β€’ 23 comments

Currently the lexer in change detection uses StringWrapper.charCodeAt()

  • in Dart it returns s.codeUnitAt() which supports UTF
  • in JS it returns str.charCodeAt() which does not support UTF

vicb avatar Feb 03 '15 10:02 vicb

the _Parser class in shim_css.js (shadow_dom_emulation) has the same limitation

vicb avatar Feb 09 '15 14:02 vicb

This, I suppose, would allow things like

<div [class.u-1/2]="expr"></div>

right?

fxck avatar Jun 09 '16 09:06 fxck

Having the same issue when rendering some text with a "ΓΌ" character in it to a component attribute.

Any updates on this issue?

ErikGrijzen avatar Jun 16 '16 09:06 ErikGrijzen

Having the same issue when rendering some text with a "ΓΌ" character in it to a component attribute.

Are you sure it is the same issue??? Please provide a reproduce scenario in plunker as it doesn't sound related.

pkozlowski-opensource avatar Jun 16 '16 09:06 pkozlowski-opensource

I did a quick test on Plunker and it works fine, see: http://plnkr.co/edit/hBnsuzFaNPpR2EnjVwlA

I made a mistake in my application by adding it as a property binding, like: <test-component [text]="Test with character ΓΌ"></test-component>

But like this it works fine: <test-component text="Test with character ΓΌ"></test-component>

My bad, sorry!

The reason I posted it here, was because it was very similar to the closed duplicated issue https://github.com/angular/angular/issues/7456

ErikGrijzen avatar Jun 16 '16 09:06 ErikGrijzen

Still doesn't work with rc.5: http://plnkr.co/edit/nx6LsdnX55FpxIc6QW5M?p=preview

penmark avatar Aug 30 '16 07:08 penmark

Bump.

Really missing the UTF support for properties in templates.

abdavid avatar Nov 07 '16 08:11 abdavid

How about this issue, any one have a solution to resolve this? I have the same problem here https://github.com/angular/angular/issues/13265, just be closed, Any suggestion?

xiexin36 avatar Dec 07 '16 05:12 xiexin36

I'd like to see full UTF-8 support for properties in templates, too. Not every programmer speaks English, and as to my experience, it's a good idea to use your native language for things like variable and method names. It helps to distinguish between your own entities and the entities defined by the framework. Usually, all the popular names are already reserved by frameworks :).

stephanrauh avatar Dec 07 '16 20:12 stephanrauh

We have been discussing that with the team. It has not be implemented earlier because:

  1. It would slow down the Lexer,
  2. It would make the code more complex.

But:

  1. We are now targeting a AoT first approach for Angular and speed has become less critical (has the lexing happens at build time only once),
  2. ES6 makes it easier to work with UTF. While it is not supported by all browsers, lexing would be done at build time (AoT) and the generated code would be able to run on all browser - we should implement it in a way to does not break JIT even for older browsers (which would not support UTF in JIT, as of today)

Does this makes sense ?

Anybody would try to try and submit a PR ?

vicb avatar Dec 07 '16 21:12 vicb

Finally I found a way to solve this problem, even it is not so nice, but it work, instand of use property name directly, we can define a function to get the property value. <div>{GetData("ε₯½")}</div> and in the component ts file. export class Test { DataContext:any; GetData(propertyName:string):any{ return this.DataContext[propertyName]; } }

xiexin36 avatar Dec 08 '16 09:12 xiexin36

Any update on this issue?

xiexin36 avatar Dec 24 '16 09:12 xiexin36

@vicb Sounds like a good plan. Is the AOT compiler fast enough to use it during the development phase? I'm using the Angular CLI, and at the moment, performance is a bit disappointing: ng serve takes 20 seconds, and ng build -aot takes more than a minute. Granted, I'm working on a slow virtual machine, but my project is still tiny, so this is still a topic.

As for the PR: I'd love to provide one, but I don't have enough spare time... I hope someone else steps in!

stephanrauh avatar Dec 24 '16 09:12 stephanrauh

Is the AOT compiler fast enough to use it during the development phase?

We are working on improving AoT speed to make it useable during development. Easing AoT is clearly on our top-priority list.

vicb avatar Dec 27 '16 18:12 vicb

@vicb How about the AOT? Any test release can try it?

xiexin36 avatar Jan 04 '17 07:01 xiexin36

Any update about this?

xiexin36 avatar Feb 18 '17 08:02 xiexin36

Two years past, have we still not support UTF-8?

xiexin36 avatar Mar 16 '17 10:03 xiexin36

@xiexin36 not yet

DzmitryShylovich avatar Mar 16 '17 10:03 DzmitryShylovich

@DzmitryShylovich Any plan about this?

xiexin36 avatar Mar 17 '17 05:03 xiexin36

Any updates on this issue?

curronieto avatar Sep 06 '17 11:09 curronieto

try this !! u can change advantage to ur unicode search the "isAsciiLetter" in angular package! i add this range for traditional chinese! " || (code >= 0x4E00 && code <= 0x9FA5)"

function isAsciiLetter(code) {
return code >= $a && code <= $z || code >= $A && code <= $Z || (code >= 0x4E00 && code <= 0x9FA5); }

TzuHuanTai avatar Mar 30 '18 00:03 TzuHuanTai

@vicb Is the issue relevant?

splincode avatar Jul 25 '18 15:07 splincode

This issue is still relevant and it is confirmed bug in the latest version of Angular, see: https://stackblitz.com/edit/angular-ivy-nuc4uz?file=src/app/app.component.ts

tl;dr; is that it is all about making non-ASCII characters in Angular expressions:

@Component({
  selector: 'my-app',
  template: '<div>{{ ζˆ‘ηš„ }} </div>',
})
export class AppComponent  {
  // Chinese character
  ζˆ‘ηš„ = 'Angular';
}

pkozlowski-opensource avatar May 08 '20 13:05 pkozlowski-opensource

@pkozlowski-opensource I have a workaround for this:

https://stackblitz.com/edit/angular-ivy-zmtxmg?file=src%2Fapp%2Fapp.component.ts

import { Component, VERSION } from '@angular/core';

@Component({
  selector: 'my-app',
  template: '<div>{{ this["ζˆ‘ηš„"] }} </div>',
})
export class AppComponent  {
  // Chinese character
  ζˆ‘ηš„ = 'Angular';
}

image

I really wish Angular Team can take care of this issue. It's been 8 years since 2015.

doggy8088 avatar Feb 02 '23 04:02 doggy8088