Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database localization

i am looking for opinions if the following problem maybe has a better/different/common solution:


I have a database for products which contains the names of the products in english (the default language of this application) and i need translations of the names if available.

Currently i have this setup:

A product table

CREATE TABLE products
(
  id serial NOT NULL,
  "name" character varying(255) NOT NULL,
  CONSTRAINT products_pkey PRIMARY KEY (id)
)

and a product localization table

CREATE TABLE products_l10n
(
  product_id serial NOT NULL,
  "language" character(2) NOT NULL,
  "name" character varying(255) NOT NULL,
  CONSTRAINT products_l10n_pkey PRIMARY KEY (product_id, language),
  CONSTRAINT products_l10n_product_id_fkey FOREIGN KEY (product_id)
      REFERENCES products (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
)

and i use the following query to retrieve a list of localized products (german in this case) with fallback to the default english names:

SELECT p.id, COALESCE(pl.name, p.name) 
from products p LEFT 
JOIN products_l10n pl ON p.id = pl.product_id AND language = 'de';

The SQL code is in postgres dialect. Data is stored as UTF-8.

like image 902
Fionn Avatar asked Oct 10 '08 00:10

Fionn


People also ask

What is SQL localization?

Localized versions of SQL Server can only be upgraded to localized versions of the same language, and cannot be upgraded to the English-language version. Localized versions of SQL Server can also be installed side by side with English-language instances of SQL Server.

What do you mean by localization?

Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a locale).

What is a localization example?

Examples of localization include changing changing z's to s's for British English. In addition to idiomatic language translation, such details as time zones, money, national holidays, local color sensitivities, product or service name translation, gender roles and geographic references must all be considered.

What is the difference between translation and localization?

Translation vs localization: what's the difference? Translation is the process of changing your text into another language, but localization is far more wide-reaching. It considers the cultural, visual and technological aspects of changing a site for users in different languages.


2 Answers

Looks good to me. The one thing I might change is the way you handle languages: that should probably be a separate table. Thus, you would have:

CREATE TABLE products_l10n
(
  product_id serial NOT NULL,
  language_id int NOT NULL,
  "name" character varying(255) NOT NULL,
  CONSTRAINT products_l10n_pkey PRIMARY KEY (product_id, language),
  CONSTRAINT products_l10n_product_id_fkey FOREIGN KEY (product_id)
      REFERENCES products (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
  CONSTRAINT products_l10n_language_id_fkey FOREIGN KEY (language_id)
      REFERENCES languages (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
)

CREATE TABLE languages
)
  id serial not null
  "language" character(2) NOT NULL
)

Besides that, I think you've got just about the best possible solution.

like image 199
Daniel Spiewak Avatar answered Sep 22 '22 04:09

Daniel Spiewak


Looks good - similar to my preferred localization technique - what about wide characters (Japanese)? We always used nvarchar to handle that.

What we actually found, however in our international purchasing operation, was that there was no consistency across international boundaries on products, since the suppliers in each country were different, so we internationalized/localized our interface, but the databases were completely distinct.

like image 42
Cade Roux Avatar answered Sep 22 '22 04:09

Cade Roux