I have greek text on a String in Dart using Polymer, why is it displayed wrongly on the browser?

懵懂的女人 提交于 2019-12-05 06:40:37

问题


I have the following String on my Dart code, using Polymer:

@observable String title = "Καλώς Ήρθατε Ξανά!";

But this is what I see on the browser:

Καλώς ΉÏθατε Ξανά!

What am I missing ?

When the text uses the regular Latin chars, everything is perfect.

Thank you in forward


回答1:


Try this:

Import:

import 'dart:convert' show UTF8;

Code:

List<int> encoded = UTF8.encode('Καλώς Ήρθατε Ξανά!');
@observable String title = UTF8.decode(encoded);

Short Code:

@observable String title = UTF8.decode(UTF8.encode('Καλώς Ήρθατε Ξανά!'));

This should encode your string as UTF8 so it shows up properly on screen.




回答2:


I had the same issue with French. Set the charset into your HTML file header (default is ISO-8859-1)

Short:

<meta charset="utf-8">

Long:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

This should solve this issue. BTW all strings in Dart are already in UTF8




回答3:


Like @Akshay comments on his response:

It must be a bug in Dartium, I found this: code.google.com/p/dart/issues/detail?id=14948

I ran it as JS and the greek String was displayed properly. (With out the need of any Encoding or else, just with the String).

So, I ran the JS version on the Chromium browser just to check... maybe it was a Browser issue.... but it ALSO WORKED!

The solution is: There is no solution... IT's a bug on the Dartium, (see link above).



来源:https://stackoverflow.com/questions/22790895/i-have-greek-text-on-a-string-in-dart-using-polymer-why-is-it-displayed-wrongly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!