I18N translation system: suggestions about the ER diagram design?
-
02-07-2021 - |
Question
I've got a simple database of products.
Each product is N:1 related to several attributes, such as material, gender, shape and so on.
Each attribute is a table (e.g. table "shapes" with square, round and other rows)
Now I'd like to "translate" each attribute, for example, I want the "square" record, to be associated with "quadrato" (it), "carré" (fr) and so on. "languages" is another table (it,fr,en) and languages can be added or removed, so having columns "it_value", "fr_value" is obviously impossible and ugly.
I'm thinking about
- create a table "TRANSLATIONS" with id, language_id and value
- create a table "LANGUAGES" with id, name
- create tables "SHAPES" and "MATERIALS" with id and other columns
- create a table (for example) "MATERIAL_TRANSLATIONS" with translation_id and material_id
- create a table "SHAPE_TRANSLATIONS" with the same idea, as above
Do you think other solutions could be more efficient or more elegant than that?
(Sorry for not posting an ER diagram too, but I'm not a so 'graphic' person! ;))
Solution
How similar are the shapes/materials tables going to be? Could you not accomplish that with a single table with a "type of attribute" (shapes/materials) and "name of attribute" (square, cotton, etc...) fieldset?
If that's the case, then I'd probably use something like:
items: id, name
languages: id, name
items_translations: item_id, language_id, name
The 'name' in the items table would be the default language (e.g. english) of your system, and any translations would be in the items_translations table's 'name' field.
OTHER TIPS
That sounds fine.
You could use a more abstract representation, but I think your explicit mapping approach is more understandable, and therefore better.