---
name: i18n
description: Internationalization with i18next for UI translations and JSONB for database content. Use when adding translations, working with localized content, or implementing multi-language features.
---
# i18n Helper
Complete internationalization guide for this application.
## Supported Languages
| Code | Language | URL Pattern |
| ---- | ----------------- | -------------- |
| `en` | English (default) | `/en/products` |
| `fr` | French | `/fr/products` |
| `id` | Indonesian | `/id/products` |
## Two Types of i18n
### 1. UI Translations (i18next)
Static strings in the interface: buttons, labels, messages.
```typescript
import { useTranslation } from 'react-i18next'
function MyComponent() {
const { t } = useTranslation()
return (
{t('Welcome')}
)
}
```
### 2. Database Content (JSONB)
Dynamic content stored in the database: product names, descriptions.
```typescript
type LocalizedString = { en: string; fr?: string; id?: string }
// In database schema
name: jsonb('name').$type().notNull()
// Usage
const productName = product.name[currentLang] || product.name.en
```
## Adding UI Translations
### 1. Add Keys to Locale Files
```json
// src/i18n/locales/en.json
{
"Welcome": "Welcome",
"Add to Cart": "Add to Cart",
"{{count}} items": "{{count}} items",
"{{count}} items_one": "1 item",
"{{count}} items_other": "{{count}} items"
}
// src/i18n/locales/fr.json
{
"Welcome": "Bienvenue",
"Add to Cart": "Ajouter au panier",
"{{count}} items_one": "1 article",
"{{count}} items_other": "{{count}} articles"
}
// src/i18n/locales/id.json
{
"Welcome": "Selamat datang",
"Add to Cart": "Tambah ke Keranjang",
"{{count}} items": "{{count}} barang"
}
```
### 2. Use in Components
```typescript
import { useTranslation } from 'react-i18next'
function CartSummary({ itemCount }: { itemCount: number }) {
const { t } = useTranslation()
return (