[我在前端页面中使用Thymeleaf,由于某种原因,我必须通过i18next.js而不是spring框架来处理i18n。
根据i18next-jquery introduction - using options in translation function,我这样写:
<span data-i18n="myKey" data-i18n-options='{ "WHERE": "TW" }'></span>
还有我的语言资源:
{ "myKey" : "User is from {{WHERE}}." }
并且html被解析并完美地显示为:
<span data-i18n="myKey" data-i18n-options='{ "WHERE": "TW" }'> User is from TW. </span>
但是当我通过Thymeleaf属性动态设置{{WHERE}}时,就无法解析它。
我尝试过 th:attrappend="data-i18n-options='{WHERE: '+ ${country} +'}'"
也 th:data-i18n-options="'{WHERE: '+ ${country} +'}'"
,不知何故,它最终像这样结束:
<span data-i18n="myKey" data-i18n-options="{WHERE: TW}">User is from .</span>
所以我想知道在Thymeleaf属性中解析json字符串有什么想法吗?
更新:我想分享我的solution,希望它可以节省别人的时间:)
th:attrappend='data-i18n-options=|{ "WHERE":"${country}"}|'
要么 th:data-i18n-options='|{ "WHERE":"${country}"}|'
请尝试这两个:
th:attrappend='data-i18n-options=|{ "WHERE":"${country}"}|'
要么th:data-i18n-options='|{ "WHERE":"${country}"}|'