我使用 intl 包来国际化我的应用程序,但是我遇到了一个问题。
有一个英文和中文的字符串:
"has $num"
"有$num个"
现在我想为
$num
部分添加一些样式,例如,将数字设置为红色。我想我需要按语言环境获取字符串,处理和拆分字符串,然后自己将其转换为 TextSpans。
有没有更简单/更聪明的方法来做到这一点?
最佳答案
好吧,实际上您可以使用 webview_flutter
中的内联 html View (引用 https://github.com/flutter/flutter/issues/19030#issuecomment-437534853 )
"has <span style='text-color:red'>$num</span>"
"有<span style='text-color:red'>$num</span>个"
只需要小心字符串插值。
关于Flutter 富文本国际化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54985859/