Explain how to use SQL to support internationalization in an application.
Instruction: Discuss the strategies and SQL features that can be used to store and retrieve data in multiple languages.
Updated
Official answer
Store translatable content separately from stable product identity. A translation table can use a primary key of (product_id, locale) and a foreign key to products, with Unicode-capable storage. Choose a consistent locale-tag convention and fallback policy rather than assuming a language alone captures every regional variation.
For PostgreSQL products(id) and product_translations(product_id, locale, name), try French then English without dropping products that lack both:
SELECT p.id, COALESCE(fr.name, en.name) AS display_name
FROM products AS p
LEFT JOIN product_translations AS fr
ON fr.product_id = p.id AND fr.locale = 'fr'
LEFT JOIN product_translations AS en
ON en.product_id = p.id AND en.locale = 'en'
ORDER BY p.id;
Uniqueness of each product/locale pair prevents duplicate output. If both names are missing the result is NULL, which the application must handle. An empty string is not NULL, and field-by-field fallback may mix languages; choose whether fallback applies per field or to an entire translation.
Test sorting, searching, normalization and locale-sensitive comparisons. Store dates/numbers in suitable native types with currency/timezone context; format them for display in the application. Bind requested locale values, and treat translation selection separately from authorization.