Skip to content

Commit cc51941

Browse files
committed
feat(PrimeOutputText): isTranslationKey prop added and i18n handling
1 parent 483fd56 commit cc51941

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/components/PrimeOutputText.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang='ts'>
22
import type { FormKitFrameworkContext } from '@formkit/core'
33
import type { PropType } from 'vue'
4+
import { useI18n } from 'vue-i18n'
45
import { useFormKitSection } from '../composables'
56
67
const props = defineProps({
@@ -10,6 +11,20 @@ const props = defineProps({
1011
},
1112
})
1213
14+
const textValue = computed(() => {
15+
const value = props.context?._value
16+
const { t } = useI18n()
17+
if (value) {
18+
if (props.context?.isTranslationKey)
19+
return t(value)
20+
else
21+
return value
22+
}
23+
else {
24+
return ''
25+
}
26+
})
27+
1328
const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection(props.context)
1429
</script>
1530

@@ -24,8 +39,8 @@ const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection
2439
:style="context?.attrs?.style"
2540
:class="context?.attrs?.class"
2641
>
27-
<span v-if="context?.html" v-html="context?._value" />
28-
<span v-else v-text="context?._value" />
42+
<span v-if="context?.html" v-html="textValue" />
43+
<span v-else v-text="textValue" />
2944
</span>
3045
<span v-if="hasSuffix" class="formkit-suffix">
3146
{{ context?.suffix }}

src/definitions/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PrimeOutputReference from '../components/PrimeOutputReference.vue'
1010
import PrimeOutputText from '../components/PrimeOutputText.vue'
1111

1212
export const primeOutputTextDefinition: FormKitTypeDefinition = createInput(PrimeOutputText, {
13-
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'html'],
13+
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'isTranslationKey', 'html'],
1414
})
1515

1616
export const primeOutputDateDefinition: FormKitTypeDefinition = createInput(PrimeOutputDate, {

0 commit comments

Comments
 (0)