Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate database strings

I have an application written for the UK market that currently only supports English (UK) and a client wants to deploy part of the application out to a non UK site and syncronise the data back to the UK HQ.

I can convert the application labels and messages using resource files and the local culture information but was wondering how you would convert the database bound data.

E.G. Here is the HQ based table

tblFault
ID ; Description
1 ; Not Functional
2 ; Build Fault
3 ; Leak
4 ; Aesthetics
5 ; Testing

If I was to translate the data to the non UK language I could just replace the descriptions but this would cause some problems if the data is unsyncronised?

Should I extend the table with another column for additional language and then alter the selection using the local culture?

tblFault
ID ; Description-EN ; Descrption-US ; Description-DE etc
1  ; Not Functional ;               ;
2  ; Build Fault    ;               ;
3  ; Leak           ;               ;
4  ; Aesthetics     ;               ;
5  ; Testing        ;               ;

What method would you recommend?

Thanks

Phil

like image 608
Phil Murray Avatar asked Jun 14 '11 13:06

Phil Murray


People also ask

How do I translate a string in SQL?

The TRANSLATE() function returns the string from the first argument after the characters specified in the second argument are translated into the characters specified in the third argument. Note: The TRANSLATE() function will return an error if characters and translations have different lengths.

What are translation strings?

The Translation Strings endpoint handles READ/UPDATE operations for the translations in a language of a specific resource. Translation strings in a resource are identified by two elements: the key and the context. The key is the actual identifier for a translation. Each file format has its own way to specify keys.

What is translation in database?

A translation memory (TM) is a database that stores "segments", which can be sentences, paragraphs or sentence-like units (headings, titles or elements in a list) that have previously been translated, in order to aid human translators.

What is use of translate in SQL?

TRANSLATE() function : This function in SQL Server is used to return the translated string of the string stated in the first argument of this function, when the characters stated in the characters argument of the above function are converted into the characters stated in the last argument i.e, translations.


2 Answers

Since you have a 1:n relationship between faults and their descriptions, the cleanest solution would be to create a subtable:

tblFault
--------

FaultID ; some other fields
      1 ; ...
      2 ; ...
      3 ; ...
      4 ; ...
      5 ; ...


tblFault_Description
--------------------

FaultID ; lang ; Description
      1 ; en   ; Not Functional
      1 ; de   ; Funktioniert nicht
      2 ; en   ; ...
like image 68
Heinzi Avatar answered Sep 22 '22 13:09

Heinzi


That's definitely one approach.

Another approach that I've used in situations like this before was to create a "LanguageId" column.

Typically I would have something like this:

StringId,  LanguageId,    Description
1            0              Hello
1            1              Hola
1            2              Bon Jour

This allow me to write a query that if string 35 (for example) doesn't have the language I'm looking for, I could still provide English. With the thought being that something is better than nothing.

The downside to this approach is composite primary keys, and some join logic.

like image 27
taylonr Avatar answered Sep 25 '22 13:09

taylonr