我使用的是vue-i18n
,我需要在中間翻譯帶有錨標記的句子。很明顯,我想保留我的翻譯html特定的標記,但如何最好地處理這個?vue-i18n翻譯中html標籤的最佳實踐?
請看下面的例子:
This is a test sentence which cannot
<a href="https://example.com" class="test-class test-another-class">be split</a>
or it will not make sense
唯一的解決辦法我能想出是:
{
"en": {
"example": "This is a test sentence which cannot {linkOpen}be split{linkClose} or it will not make sense"
}
}
,然後分量模板
<p v-html="$t('example', {
'linkOpen': `<a href="https://example/com" class="test-class test-another-class">`,
'linkClose: '</a>'
})
"></p>
不但是正是優雅...
編輯:我測試了這個,它並沒有實際工作(不能把HTML中的參數),所以現在我真的沒有想法!