Is there any plan to support basic markdown? #681
Replies: 3 comments 1 reply
-
|
Probably, if you use markdown, you need to combine a parser like markdown-it with the Vue component. |
Beta Was this translation helpful? Give feedback.
-
|
@kazupon could you clarify your last post please? I also think that it could be very convenient to have a way to easily add 99% of the component interpolations in my website are just there to add a To get simply this:
Seems overkill. Would be awesome to be able to write it somehow like this: Even if it is not markdown. Something like |
Beta Was this translation helpful? Give feedback.
-
|
There are multiple ways to make an API that will solve this problem. Option 1: using a map with vnodes (does not look ugly, supports named placeholders)<template>
<Translate keypath="my-message" tag="label" :nodes="nodes" />
</template>
<i18n>
{
"my-message": "This is my <strong>message</strong>. And you can click this <link>text</link>"
}
</i18n>
<output>
<label>
This is my <strong>message</strong>. And you can click this <a href="https://vuejs.org">text</a>
</label>
</output>
<script lang="ts">
import { defineComponent, h } from '@vue/runtime-core'
import { VNode } from 'vue'
export default defineComponent({
setup() {
const nodes: Record<string, VNode> = {
link: h('a', { href: 'https://vuejs.org' }),
strong: h('strong'),
}
return { nodes }
},
})
</script>Option 2: using each named slots single vnode (looks ugly, supports named placeholders)<template>
<Translate keypath="my-message" tag="label">
<template #strong>
<strong />
</template>
<template #link>
<a href="https://vuejs.org" />
</template>
</Translate>
</template>
<i18n>
{
"my-message": "This is my <strong>message</strong>. And you can click this <link>text</link>"
}
</i18n>
<output>
<label>
This is my <strong>message</strong>. And you can click this <a href="https://vuejs.org">text</a>
</label>
</output>Option 3: using default slot vnodes (looks nice but no named placeholders)<template>
<Translate keypath="my-message" tag="label">
<strong />
<a href="https://vuejs.org" />
</Translate>
</template>
<i18n>
{
"my-message": "This is my <0>message</0>. And you can click this <1>text</1>"
}
</i18n>
<output>
<label>
This is my <strong>message</strong>. And you can click this <a href="https://vuejs.org">text</a>
</label>
</output>Option 4: looks better but is impossible because of how slots work<template>
<Translate keypath="my-message" tag="label">
<strong #strong />
<a #link href="https://vuejs.org" />
</Translate>
</template>
<i18n>
{
"my-message": "This is my <strong>message</strong>. And you can click this <link>text</link>"
}
</i18n>
<output>
<label>
This is my <strong>message</strong>. And you can click this <a href="https://vuejs.org">text</a>
</label>
</output>
const FancyLink = defineComponent({ /* ... */ })
const nodes: Record<string, VNode> = {
link: h(FancyLink, { href: 'https://vuejs.org' }),
strong: h('strong'),
}One can use basic interpolation to replace all simple placeholders ( To be continued and brainstormed
Maybe I will look soon into this feature request |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I was wondering if it could be possible to support basic markdown like
boldunderlineanditalicto prevent translations to be polluted by too much interpolations?Beta Was this translation helpful? Give feedback.
All reactions