I'm working on multi-lang website. Trying to design optimal db schema for this purpose.
As you see, there are 2 tables: langs
and menu
. My idea is following:
For ex. lets take a look at multi-language navigation generation from MySQL table. In PHP backend, while generating navigation from database
menu
table's rowlangs
(by name
field of menu
table ) and get data from defined language's column (for ex. en, ru)How do you think, is it optimal way, or is there more efficient solution? Please, give me database related answers, not file. (for ex. gettext,... etc)
It would be better if the langs
table contained a language
column, with one row for each translation. This allows you to add another language later and only have to apply data changes (rather than having to re-write queries).
As you've already implied, performing a left join and falling back to a default language held directly in the menus
table is also a good idea (in which case, you don't need to hold a translation for e.g. en
in the langs
table, since the english version will always be available).
You may also want to consider storing country-specific translations (if, say, there are multiple spanish speaking countries where the translations can be different), and following a fallback strategy of finding: language-country
, language
, English
translations.
You can normalize further like so:
Tables that reference strings then refer to the string by tokenname.id as a foreign key.
Note that you will need some kind of mini templating language for text localizations.