Skip to content

Commit

Permalink
remove runtime vt function
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Jun 27, 2024
1 parent b87b64e commit 8ddc0b1
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions packages/vue/src/components/vt.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import { type MessageDescriptor } from "@lingui/core"
import { generateMessageId } from "@lingui/message-utils/generateMessageId"

import { useI18n } from "../plugins/lingui"
import { type MacroMessageDescriptor } from "@lingui/core/macro"

//

function isTD(strings: unknown): strings is TemplateStringsArray {
return Array.isArray(strings)
}

export function vt(descriptor: MacroMessageDescriptor): string
export function vt(
stringsOrMD: TemplateStringsArray | MessageDescriptor,
...args: Array<unknown>
) {
const i18n = useI18n()
if (isTD(stringsOrMD)) {
const message = stringsOrMD.reduce((msg, current, index) => {
if (index === 0) {
return current
}
return `${msg}{${index - 1}}${current}`
}, "")
const values: Record<string, unknown> = {}
for (let index = 0; index < args.length; index++) {
values[index] = args[index]
}
return i18n.t(generateMessageId(message), values)
}
return i18n.t(stringsOrMD.id, stringsOrMD.values, {
message: stringsOrMD.message || "fallback message",
})
}
literals: TemplateStringsArray,
...placeholders: any[]
): string
export function vt(...args: any[]): any {}

/**
* Internal method used by Vue macro
* Internal runtime used by Vue macro
* @internal
*/
;(vt as any)._ = (descriptor: MessageDescriptor) => {
const i18n = useI18n()
Expand Down

0 comments on commit 8ddc0b1

Please sign in to comment.