@nitra/tfm
TypeScript icon, indicating that this package has built-in type declarations

1.7.0 • Public • Published

@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>

usage with node

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 })

/@nitra/tfm/

    Package Sidebar

    Install

    npm i @nitra/tfm

    Weekly Downloads

    99

    Version

    1.7.0

    License

    MIT

    Unpacked Size

    4.35 kB

    Total Files

    7

    Last publish

    Collaborators

    • vitaliytv