@nitra/tfm
v2.3.1
Published
Vite translate helper
Downloads
807
Readme
@nitra/tfm
usage with Vite
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>