introduce markup placeholders (html, rich text, components, dates) #913
Replies: 3 comments 11 replies
-
We have a longer RFC. Feel free to comment on the Google Doc https://docs.google.com/document/d/1uhLrrwKPsenyNsDvZqCl6UXJc5ZBVQYkzn7k5yBuVy0/edit#heading=h.hv9mugtjvm53 |
Beta Was this translation helpful? Give feedback.
-
There are two "levels" at which we can introduce "Components".
Markup shouldn't be that much of a challenge. We can just return markup from the message & tell developers to use their framework's method of rendering stirngs as html However, I don't see a clear path to rendering full-blown components with paraglide's current approach. In some frameworks rendering components isn't possible from a This leaves us with two options:
Neither one is good. We'll have to come up with something |
Beta Was this translation helpful? Give feedback.
-
Simple way to introduce placeholders would be to compile message to arbitrary array instead of a string. For example having a translation: {
"hello": "Hello {world}!"
} It could be compiled into function hello(params: { world: unknown }) {
return ['Hello ', params.world, '!'];
} This way when using in a React or Vue code, you can put a valid Virtual Dom node as a parameter: <p class="paragraph">
{{ hello({ world: <b>world</b> }) }}
</p> To have a single way of doing things, we could also introduce a simple translation function, to render these arrays as strings: type Translation<P> = (params: P) => unknown[];
function t<P>(translation: Translation<P>, params: P) {
return translation(params).join('');
} And use it like: const helloWorld = t(hello, { world: 'world' }); |
Beta Was this translation helpful? Give feedback.
-
💡 Upvote and subscribe to this issue to increase prioritization.
Problem
Users can not use markup placeholders.
See this long thread #1959 (reply in thread)
And this one from https://discord.com/channels/897438559458430986/1110687789395226716/1110903944143712338:
Proposal
Add markup placeholders.
From the message format working group https://github.com/unicode-org/message-format-wg/blob/main/spec/syntax.md#markup-elements
Beta Was this translation helpful? Give feedback.
All reactions