Re: How to store different languages
Date: Mon, 22 Apr 2019 17:52:39 +0200
Message-ID: <5cbde345$0$22344$e4fe514c_at_news.xs4all.nl>
On 22-4-2019 17:25, ^Bart wrote:
> Before to start a new post I should say thanks to all people who reply
> (it's better to say help!!!) me! :)
>
> I have four tables, one named "ingredients" where I have a list of them
> in english (I thought to set the main language english), another table
> named "languages" where I store user's languages and "ingredient_langs"
> where I store every translation.
>
> Spanish user and Italian user will read ingredient_langs signed as
> Spanish and Italian (FK_id_language 2-3) but an English user what will
> read? Should I copy same values from "ingredients" to "ingredient_langs"
> and set them with FK_id_language 1 (english)?.
>
> ingredients
[Quoted] Add a language_id to every table that has descriptions
so for Inredients:
ingredients
id | language | name
1 | 0 | milk 2 | 0 | spelt 3 | 0 | onion
Also define a 'default' language (i did choose to make '0' the default language)
Other languages can be added (i.e. 1='Dutch')
1 | 1 | melk 4 | 1 | boter 5 | 1 | eieren
This can, of course, be 'beautified' with a foreign key, so you can only create a dutch translation for an ingredient which has an English text.
SELECT ingredient.name
from ingredients, users
[Quoted] where id=3 and language_id = users.language_id
order by language_id desc
limit 1
This should give description in language of user, and when the description in the language of the user does not exist it will show the default ('0') description.
-- LuukReceived on Mon Apr 22 2019 - 17:52:39 CEST