How to get translations as object/array with vue-i18n-bridge ? #1387
ricardo17coelho
started this conversation in
General
Replies: 2 comments 1 reply
-
@kazupon maybe u have an idea 😊😜 |
Beta Was this translation helpful? Give feedback.
1 reply
-
I created this plugin in import { defineNuxtPlugin } from '#app'
import { useI18n, type VueMessageType } from 'vue-i18n'
export default defineNuxtPlugin(() => {
const translateDeep = (resource: unknown, currentKeypath: string): unknown => {
if (useI18n().te(currentKeypath)) {
return useI18n().rt(resource as VueMessageType)
} else if (Array.isArray(resource)) {
return resource.map((r, index) => translateDeep(r, `${currentKeypath}.${index}`))
} else if (typeof resource === 'object') {
return Object.fromEntries(
Object.entries(resource as { [s: string]: unknown }).map(([key, value]) => [
key,
translateDeep(value, `${currentKeypath}.${key}`),
])
)
} else {
return undefined
}
}
const td = <T>(key: string): T => translateDeep(useI18n().tm(key), key) as T
return {
provide: { td },
}
}) Note that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to integrate
vue-i18n-bridge
into my project.Vue 2.7
andvue-i18n@8
I followed this migration/examples: https://vue-i18n.intlify.dev/guide/migration/vue2.html
On my project i have some translations like:
where i get the items and display it as list:
After install
vue-i18n-bridge
and initialize it like the example above, getting the items no longer works.i'm getting this warning:
After search in the issues, i found this related issues:
but it looks like
tm
andrt
are not available.How can i do this ?
Beta Was this translation helpful? Give feedback.
All reactions