Raw translation? #166
-
I've got a specific use case (though I don't think it's rare) where I want to embed a (localized) link inside a translation, something like this would do: {
"payment_accept_terms": "By proceeding, you confirm that you've read and accepted our <a href=\"http://example.org/en/terms\">terms and conditions</a>",
} Where the My current solutionI can fix this with component interpolation, but it feels weird and cumbersome. First, I need to get the {
"payment_accept_terms": "By proceeding, you confirm that you've read and accepted our <a>terms and conditions</a>",
} Then, I add the urls as a separate key: {
"urls": {
"terms_and_conditions": "https://example.org/en/terms"
}
} And finally, I use component interpolation at the call site: {t!(i18n, payment_accept_terms, <a> = move |it| view!(<a href=t!(i18n, urls.terms_and_conditions)>{it}</a>))} My questionIs there any nicer way of doing this? Maybe something like a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
That does look awfull yes... Nicest thing I can think of is #[component]
fn TermsAndConditionsLink(children: Children) -> impl IntoView {
let i18n = use_i18n();
view! {
<a href=t!(i18n, urls.terms_and_conditions)>
{children}
</a>
}
}
t!(i18n, payment_accept_terms, <a> = <TermsAndConditionsLink />) I'll think of a way to make that easier |
Beta Was this translation helpful? Give feedback.
-
I've found a very suitable workaround for me: <p inner_html={t!(i18n, contact.newsletter.choice)}/> Where the translation is: "contact": {
"newsletter": {
"choice": "I want to recieve special discounts and offers and I accept the <a href=\"#\">privacy policy</a>"
},
} (Sorry I don't have a smaller example, this is what I was working on right now) Basically, having the raw html in the translation, wrap it in a component and insert it using |
Beta Was this translation helpful? Give feedback.
That does look awfull yes...
Nicest thing I can think of is
I'll think of a way to make that easier