I have greek text on a String in Dart using Polyme

2020-06-30 03:58发布

问题:

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