Id like to program a multi-language application with play!. I never did that before so im looking for some advice how to do it right the first place.
the task:
lets assume i have a simple application with questions and answers. imagine it like a survey. Depending one the language the user chooses the questions and the answers are displayed in the correct language.
For better unstanding the model would look like:
question: id, questionString
answer: id, fk_questionId, answerString, isRightBool
As u see a usual 1:n relation. But how to approach now the multi language support?
- An idea would be duplicating the whole database…that idea seems simple but ugly because of the additional overhead for later changes…would be a nightmare i guess.
- additional fields like questionStringGerman, questionStringEnglish. Dont like that idea either…
- Additional table for each modelclass with an 1:n relation. Like question_lang, and answer_lang. Colums are the languages. Seems easier to handle.
- One table for all translations. Colums are the languages. Seems the easiest but hard to handle for correction.
Which approach is the best for dynamic translation. Maybe i miss something. Would be glad if some could tell me what the riht approach is to approach that problem.
Thx in advance!
I’d personally have as follows:
I’m torn between using an Id for the Translation and a UniqueName (Key) – Id is probably marginally beneficial in terms of performance but using a Meaningful Unique key makes development easier (eg Set something to
WelcomeTextand let the system look up the translation is far cleaner than setting it to16)Also, Keys are more portable if you’re adding/deleting/duplicating translations, especially across multiple database instances (different environments).
In Response to your comments on the other answer, for when no language is selected, you could add weightings in the
Languagetable itself or associate aLanguageIdwith the user account. You could also (if you want to be clever) attempt to guess based on the location of the user (but ofc you should always give them the option to change – nothing more annoying than being redirected togoogle.eswhen you’re in Spain).In any case, your method to do the translation should do this for you – eg your app just makes a
GetTranslation('WelcomeText')– YourGetTranslation()method can then look up the appropriate language to use and get the correctstring.