Default language can be set in:
import.meta.env.VITE_TFM_DEFAULT
If VITE_TFM is set, store will be disable
example in web:
<template>
<div>Мова: {{ langStore.code }}</div>
<button @click="setEnglish()">Set english (base)</button>
<button @click="setLatvian()">Set latvian</button>
<button @click="setUkrainian()">Set ukrainian</button>
<div>{{ t`Hello Sun ${langStore.code} !` }}</div>
<router-view />
</template>
<script setup>
import tf from '@nitra/tfm'
import { useLangStore } from '@nitra/tfm/store'
const langStore = useLangStore()
const tr = {
'Hello Sun ': { uk: 'Привіт Сонечко ', lv: 'Sveika Saulīte ', ee: 'Tere Päike ' }
}
const t = tf.bind({ tr })
const setEnglish = () => {
langStore.code = 'en'
}
const setUkrainian = () => {
langStore.code = 'uk'
}
const setLatvian = () => {
langStore.code = 'lv'
}
</script>
import tf from '@nitra/tfm'
import Fastify from 'fastify'
const fastify = Fastify()
const tr = {
'Привіт Сонечко ': { en: 'Hello Sun ', lv: 'Sveika Saulīte ', ee: 'Tere Päike ' }
}
// Declare a route
fastify.post('/', {}, function (req, reply) {
const t = tf.bind({ tr, lang: req.headers.lang })
reply.send({ result: t`Привіт Сонечко ` })
})
// Run the server!
fastify.listen({ port: 3000 })