what’s the best way to localize a database table, holding for example a Country?
1 Flat Table
CountryID|Code|NameEN|NameIT
----------------------------
1 |IT |Italy |Italia
SELECT CountryID, Code, NameEN AS Name
FROM Countries
2 Joined Tables
CountryID|Code
--------------
1 |IT
CountryID|LocalizationCode|Name
---------------------------------
1 |EN |Italy
---------------------------------
2 |IT |Italia
SELECT CountryID, Code, Name
FROM Countries INNER JOIN CountriesLoc ON Countries.CountryID = CountriesLocs.CountryID
WHERE LocalizationCode = 'EN'
Thank you!
I recommend going with the second option, although you appear to have some data-typos.
Country:
Localized_Country:
Which you then query like so:
Wrap that (or something similar) up in a view, and you’re golden.
Some recommendations:
You may want to push
Language(or some other type ofLocaleconcept) into it’s own table. The key can either be an auto-increment value, or the international characters, doesn’t much matter which.Make sure to put a unique constraint on
(CountryId, LanguageCode), just in case. And never forget your foreign keys.