gpt4 book ai didi

internationalization - Polymer.dart 中国际化字符串中的 HTML 标签

转载 作者:行者123 更新时间:2023-12-04 12:08:41 25 4
gpt4 key购买 nike

我在 Polymer 元素中显示国际化字符串,如下所示:

<div>
<span class="title">{{title}}</span>
<br/><br/>
<span class="subtitle">{{subtitle1}}</span>
<br/>
<span class="content">{{paragraph1}}</span>
<br/><br/>
<span class="subtitle">{{subtitle2}}</span>
<br/>
<span class="content">{{paragraph2}}</span>
</div>

...并具有以下 Dart 代码:

@observable String title;
@observable String subtitle1;
@observable String paragraph1;
@observable String subtitle2;
@observable String paragraph2;

//...

void onUpdateLocale(_locale) {
title = getTitle();
subtitle1 = getSubtitle1();
paragraph1 = getParagraph1();
subtitle2 = getSubtitle2();
paragraph2 = getParagraph2();
}

//...

getTitle() => Intl.message('MY TITLE', name:'title',
desc: 'This is my title',
args: [],
examples: {'None' : 0});
getSubtitle1() => Intl.message('Subtitle 1', name:'subtitle1',
desc: 'This is my first subtitle',
args: [],
examples: {'None' : 0});
getParagraph1() => Intl.message('This is my first paragraph',
name:'paragraph1',
desc: 'This is the my first paragraph',
args: [],
examples: {'None' : 0});
getSubtitle2() => Intl.message('Subtitle 2', name:'subtitle1',
desc: 'This is my second subtitle',
args: [],
examples: {'None' : 0});
getParagraph2() => Intl.message('This is my second paragraph',
name:'paragraph2',
desc: 'This is the my second paragraph',
args: [],
examples: {'None' : 0});

有没有办法结合 title , subtitle1 , paragraph1 , subtitle2 , 和 paragraph2成一个可观察变量,其中包括 <br><span>标签的值(value)?

最佳答案

更新

Dart Polymer 1.0 的现成元素是 bwu-bind-html

更新

Polymer 现在为此提供了开箱即用的支持

 this.injectBoundHTML('<div>your HTML goes here ${someBoundFieldValue}</div>);



这是 <safe-html>的代码我正在使用的标签。

library safe_html;

import 'dart:async';
import "dart:html";

import "package:polymer/polymer.dart";


@CustomTag("safe-html")
class SafeHtml extends PolymerElement {

@published String model;

NodeValidator nodeValidator;
bool get applyAuthorStyles => true;
bool isInitialized = false;

SafeHtml.created() : super.created() {
nodeValidator = new NodeValidatorBuilder()
..allowTextElements();
}

void modelChanded(old) {
if(isInitialized) {
_addFragment();
}
}

void _addFragment() {
var fragment = new DocumentFragment.html(model, validator: nodeValidator);
$["container"].nodes
..clear()
..add(fragment);

}

@override
void attached() {
super.attached();
Timer.run(() {
_addFragment();
isInitialized = true;
});
}
}

<!DOCTYPE html>

<polymer-element name="safe-html">
<template>
<div id="container"></div>
</template>

<script type="application/dart" src='safe_html.dart'></script>

</polymer-element>

用法:

<safe-html model="{{someField}}></safe-html>

关于internationalization - Polymer.dart 中国际化字符串中的 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20868296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com