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 page
useAsyncData runs the load on the server and passes plain JSON to the client.
pages/[locale]/index.vue<script setup lang="ts">import { computed } from "vue";import { createStrings } from "lefine/server";import { createTranslator } from "lefine/strings";const strings = createStrings({ project: "app_..." });const route = useRoute();const locale = computed(() => String(route.params.locale ?? "en"));// Runs on the server and passes plain JSON to the client.const { data: props } = await useAsyncData(() => strings.load(locale.value, ["home"]), { watch: [locale] });const t = computed(() => (props.value ? createTranslator({ ...props.value, namespace: "home" }) : null));</script><template> <h1 v-if="t">{{ t("greeting", { name: "World" }) }}</h1></template>