Dartlang with polymer character encoding

筅森魡賤 提交于 2019-12-18 07:20:09

问题


I wrote a snippet and not working with national characters. The "A törzsszám"... text appear "törzsszám" with my loginstatus field.

Main html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="hu" xml:lang="en">
  <head>
  <meta charset="utf-8">
....

Login.html

<polymer-element name="login-element" attributes="loginrow">
  <template>
    ...
    <div>
      <input type="text" value="{{torzsszam}}">
      ...
      <br>
      <span>({{loginstatus}})</span>
    </div>
  </template>
  <script type="application/dart" src="login.dart"></script>
</polymer-element>

..and the login.dart snippet:

@CustomTag('login-element')
class Login extends PolymerElement {
  bool loginned = false;
  @published String torzsszam = "";
  @published String password = "";
  @published String loginstatus = "-";

  ...

  void log_in_click() {
    loginstatus="LOGIN";
    loginned = false;
    if (torzsszam != "" ) {
      if (torzsszam.length>8) {

        loginstatus='A törzsszám legfeljebb 8 számjegyből áll!';
      } else {

What can I do...


回答1:


A while ago I posted the code for a <safe-html> tag at HTML Tags Within Internationalized Strings In Polymer.dart (original form Bind content containing html tags)

Using this polymer element shows proper characters.

Your login.html would then look like:

<link rel="import" href="../packages/safe_html/safe_html.html">

<polymer-element name="login-element" attributes="loginrow">
  <template>
    ...
    <div>
      <input type="text" value="{{torzsszam}}">
      ...
      <br>
      <span>(<safe-html model="{{loginstatus}}></safe-html>)</span>
    </div>
  </template>
  <script type="application/dart" src="login.dart"></script>
</polymer-element>



回答2:


Ups,... I tried some solutions:

1.solution: change the encoding properties in login.dart from utf-8 to ISO-8859-2

2.solution: I created another file (consts.dart)

class consts {
  static String loginstatus_err8 = "A törzsszám legfeljebb 8 számjegyből áll!";  
  static String loginstatus_OK = "Belépve";  
  static String loginstatus_emptytorzsszam = "A törzsszámot ki kell tölteni";
}

I used this in login.dart, and it worked :) I'm happy.

...
        loginstatus=consts.loginstatus_err8;
      } else {

        loginstatus=consts.loginstatus_OK;
...


来源:https://stackoverflow.com/questions/21134778/dartlang-with-polymer-character-encoding

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