Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to handle I18N in lookup tables?

In a multilanguage application with lookup tables, what's the best way to handle translations?

For example for a country lookup table, a US user should see English country names, as a German should see German names. But still their IDs should be the same.

I can think of the following:

  • Add a different lookup table for every language
  • Use a single lookup table with multiple entries for the same country flagged according to its language.
  • Get rid of all lookup tables and do all lookups by program code
  • [Any other idea I didn't think of?]
like image 996
Daniel Rikowski Avatar asked Sep 01 '09 18:09

Daniel Rikowski


People also ask

Should I use lookup table?

Lookup tables provide the essential function of helping you maintain data integrity in your database environment. For example, if you have users entering their gender into a data item, the table that contains the Gender item can reference a lookup table to verify that only the value M or F is used.

How does a lookup table works?

A lookup table is an array of data that maps input values to output values, thereby approximating a mathematical function. Given a set of input values, a lookup operation retrieves the corresponding output values from the table.

How do you localize a database?

THERE ARE FOUR METHODS THAT ARE USED TO LOCALIZE DATABASES: Row localization – copies the original row for each language. Field localization – updates the values of the localized fields. Table localization – adds new language tables for each table. Database cloning – creates a copy of the database for each language.

What is I18n in Ruby?

The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.


1 Answers

The big question here is - can translations can be altered by end users?

If the answer is "NO", resource bundles are easier and faster to use than tables. Instead of actual text your tables will contain resource key (or you could use primary key for that purpose if it's textual rather than numeric) and appropriate resource bundle will contain the translation.

If the answer is "YES", you have to store translations in the database. I have found, however, that the easiest approach in this scenario is to mimic the above resource bundle functionality in the database - e.g. have a single table with "locale", "resource key", "resource value" columns that all other tables will use to look up actual localized text.

like image 121
ChssPly76 Avatar answered Sep 23 '22 04:09

ChssPly76