Skip to content

Commit

Permalink
feat(PrimeOutputText): isTranslationKey prop added and i18n handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed Oct 3, 2024
1 parent 483fd56 commit cc51941
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/components/PrimeOutputText.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang='ts'>
import type { FormKitFrameworkContext } from '@formkit/core'
import type { PropType } from 'vue'
import { useI18n } from 'vue-i18n'
import { useFormKitSection } from '../composables'
const props = defineProps({
Expand All @@ -10,6 +11,20 @@ const props = defineProps({
},
})
const textValue = computed(() => {
const value = props.context?._value
const { t } = useI18n()
if (value) {
if (props.context?.isTranslationKey)
return t(value)
else
return value
}
else {
return ''
}
})
const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection(props.context)
</script>

Expand All @@ -24,8 +39,8 @@ const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection
:style="context?.attrs?.style"
:class="context?.attrs?.class"
>
<span v-if="context?.html" v-html="context?._value" />
<span v-else v-text="context?._value" />
<span v-if="context?.html" v-html="textValue" />
<span v-else v-text="textValue" />
</span>
<span v-if="hasSuffix" class="formkit-suffix">
{{ context?.suffix }}
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import PrimeOutputReference from '../components/PrimeOutputReference.vue'
import PrimeOutputText from '../components/PrimeOutputText.vue'

export const primeOutputTextDefinition: FormKitTypeDefinition = createInput(PrimeOutputText, {
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'html'],
props: ['prefix', 'suffix', 'iconPrefix', 'iconSuffix', 'isTranslationKey', 'html'],
})

export const primeOutputDateDefinition: FormKitTypeDefinition = createInput(PrimeOutputDate, {
Expand Down

0 comments on commit cc51941

Please # to comment.