gpt4 book ai didi

java - 检查 tpl-if-tag,gxt 模板中的字符是否为中文

转载 作者:行者123 更新时间:2023-12-01 22:37:22 26 4
gpt4 key购买 nike

在我的 java gxt-项目中,我有一个模板,其中有以下 tpl 标记,这些标记根据父标题决定标题是否必须为斜体。

                <tpl if="titleORG != &quot;&quot;">
<tpl if="ParentTitleORG == &quot;&quot;"><i></tpl>
<b>{titleORG}<tpl if="subtitleORG != &quot;&quot;">: {subtitleORG}</tpl></b>
<tpl if="ParentTitleORG == &quot;&quot;"></i></tpl>
</tpl>
<tpl if="titleEN != &quot;&quot;">
<tpl if="officialTitleTranslation"> / {titleEN}<tpl if="subtitleEN != &quot;&quot;">: {subtitleEN}</tpl></tpl>
</tpl>.

最近我收到一个票,如果不是中文或韩文,是否可以只将标题设为斜体。

知道吗,我该如何检查?

谢谢

埃里克

最佳答案

您必须在传递到 XTemplate 的类中检查它。

添加一个 boolean 值(我将其称为 ckj)并将其设置在构造函数中。 [使用 GXT 文档中的 Person 示例]

  public class Person {
private String name;
private boolean ckj;
private int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
this.ckj=containsJapanese(name);
}
public String getName() {
return name;
}
public int getAge() {
return age;
}

public boolean containsCKJ(String s) {
return s.codePoints()
.anyMatch(codepoint -> (Character.UnicodeScript.of(codepoint) == Character.UnicodeScript.HAN
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_STROKES
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.ENCLOSED_IDEOGRAPHIC_SUPPLEMENT
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.KANGXI_RADICALS
|| Character.UnicodeBlock.of(codepoint) == Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS

));
}
}

然后您可以在模板中使用 if 表达式。

 <tpl if="!ckj">
//italics
<tpl if="ckj">
//no italics

有关检查 CKJ 字符的更多讨论请参见 Differentiating CJK languages (Chinese, Japanese, Korean) in Android

关于java - 检查 tpl-if-tag,gxt 模板中的字符是否为中文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58519441/

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