Set it up
- 01
Install
One package. lefine/server and lefine/strings import no React and no Next.
terminalbashnpm install lefine - 02
Load and translate
createStrings takes your app id; load returns plain JSON; createTranslator gives you t.
strings.ts// any framework, server or browserimport { createStrings } from "lefine/server";import { createTranslator } from "lefine/strings";const strings = createStrings({ project: "app_..." }); // one per appconst props = await strings.load(locale, ["home"]); // plain JSONconst t = createTranslator({ ...props, namespace: "home" }); - 03
Use it in a component
Keep the translator in a computed and load again when the locale changes.
Home.vue<script setup lang="ts">import { computed, ref, watch } from "vue";import { createStrings, type StringsProps } from "lefine/server";import { createTranslator } from "lefine/strings";const strings = createStrings({ project: "app_..." });const locale = ref("en");const props = ref<StringsProps | null>(null);watch(locale, async (l) => (props.value = await strings.load(l, ["home"])), { immediate: true });const t = computed(() => (props.value ? createTranslator({ ...props.value, namespace: "home" }) : null));</script><template> <h1 v-if="t">{{ t("greeting", { name: "World" }) }}</h1></template>