Full answer
text
products(id PK, sku, price_minor)
product_translations(product_id FK, locale TEXT, name, description,
PRIMARY KEY (product_id, locale))Reading in Hindi with English fallback:
text
SELECT p.id, COALESCE(hi.name, en.name) AS name
FROM products p
LEFT JOIN product_translations hi ON hi.product_id = p.id AND hi.locale = 'hi'
LEFT JOIN product_translations en ON en.product_id = p.id AND en.locale = 'en';Alternatives:
- Columns per language (
name_en,name_hi) are simple for two fixed languages but need schema changes for each new one. - A JSON column (
{"en": "...", "hi": "..."}) is compact but harder to constrain and index per language.
Search across languages may need per-language full-text configurations. Locale codes should follow a standard (BCP 47, such as 'en', 'hi', 'pt-BR'). The queries are illustrative and were not run here.
Key points
- Translations table keyed by entity and locale
- Fallback via LEFT JOIN and COALESCE
- Columns per language do not scale
- JSON is compact but harder to constrain
- Use standard locale codes
Common mistakes
- Duplicating whole product rows per language
- No fallback for missing translations
Follow-ups
- How would you find products missing a translation?
- How would full-text search work per language?
Tips
- Show the fallback join