{{ name | capitalize }}
at runtime using safe substitution pipelines. {{ ?.isAdmin ? 'Admin' : 'User' }}
. [plural.key]
. {{ !.role k:'admin' v:'Admin' }}
. import { createTranslation } from '@smaiill/trin'
// Example 1: Basic placeholder with capitalize filter
const { t } = createTranslation(
{
en: {
greeting: 'Hello, {{ name | capitalize }}.',
},
},
{
locale: 'en',
},
)
t('greeting', { name: 'john' })
// Output: Hello, John.
import { createTranslation } from '@smaiill/trin'
// Example 2: Ternary conditional rendering
const { t } = createTranslation(
{
en: {
status: "{{ ?.isLoggedIn ? 'Welcome back' : 'Please log in' }}",
},
},
{
locale: 'en',
},
)
t('status', { isLoggedIn: false })
// Output: Please log in
t('status', { isLoggedIn: true })
// Output: Welcome back
import { createTranslation } from '@smaiill/trin'
// Example 3: Pluralization with item count
const { t } = createTranslation(
{
en: {
itemCount: 'You have {{ itemCount }} item[plural.itemCount].',
},
},
{
locale: 'en',
},
)
t('itemCount', { itemCount: 1 })
// Output: You have 1 item.
t('itemCount', { itemCount: 3 })
// Output: You have 3 items.
import { createTranslation } from '@smaiill/trin'
// Example 4: Role-based view with key-value matching
const { t } = createTranslation(
{
en: {
roleView: '{{ !.role k:"admin" v:"Admin Panel" k:"user" v:"User Dashboard" }}',
},
},
{
locale: 'en',
},
)
t('roleView', { role: 'admin' })
// Output: Admin Panel
t('roleView', { role: 'user' })
// Output: User Dashboard