user3333203
user3333203

Reputation: 11

SQL Database with two languages

I am not an expert in the SQL and database in general.

I am creating an android application with the feature of multi-languages for both the interfaces and the content itself.

my question is for the content language: is there any way to retrieve data from the database which is containing only one language (English),like translating the content to the other language option ??

because I think it is not efficient to store both languages in the database.

thanks in advance,

Upvotes: 1

Views: 344

Answers (1)

Thorsten Kettner
Thorsten Kettner

Reputation: 95052

Text belonging to the client app is usually stored with that app, so you don't have to load "OK" and "Cancel" in the appropriate language from database only to show some buttons. (But you could store this in a database of course, if you wanted to.)

Content data on the other hand is usually stored in the database. It doesn't make much sense, to store part of it in the database and part of it somewhere else. If you store products in your database, then store the text necessary with it. It belongs there. As to accessing data, this is not slow, because you don't retrieve text in all languages, but only in the language desired.

Here is a typical table design:

create table product
(
  id number(10),
  buying_price number(6,2),
  selling_price number(6,2),
  id_vat number(1),
  ...
);

create table product_name
(
  id_product number(10),
  language_iso varchar(2), -- 'en', 'de', 'fr', ... or chose another code
  text varchar(100)
);

create table product_description
(
  id_product number(10),
  language_iso varchar(2),
  text varchar(2000)
);

You could also decide for a more generic design:

create table products
(
  id number(10),
  tranlation_number number(10),
  buying_price number(6,2),
  selling_price number(6,2),
  id_vat number(1),
  ...
);

create table translations
(
  tranlation_number number(10),
  content_name varchar2(30), -- 'PRODUCT_NAME', 'PRODUCT_DESCRIPTION', ...
  language_iso varchar(2), -- 'en', 'de', 'fr', ... or chose another code
  text varchar(4000)
);

There are more possibilities. Whichever you chose, accessing data simply means a join and a constant for the language. There should be no problem with performance at all. And data is where it belongs.

Upvotes: 1

Related Questions