ts
The core API that you will be using most when using Terai, is the ts
function.
The ts
function is based in tagged templates, a more advanced form of
template literals in Javascript, each call representing representing a translatable plain-text string.
💡
In essence, ts
is just a string that receives a string and returns its
equivalent in the corresponding dictionary.
Usage
Terai provides a set of utils for obtaining the ts
function, depending on the framework you're using:
useFormat
: for ReactgetFormat
: for Node
import { useTs } from '@terai/react'
export function Example() {
const { ts } = useTs()
return (
<div>
<p>{ts`Hello, world!`}</p>
</div>
)
}
Variables
If you know how to use a variable in a template string, you already know how to use variables in ts
.
import { useTs } from '@terai/react'
export function Example() {
const { ts } = useTs()
const name = 'world'
return (
<div>
<p>{ts`Hello, ${name}!`}</p>
</div>
)
}