开发者

Localize table data

For example: I have t开发者_JAVA技巧able with some codes:

1, Blue, This is blue color
2, Red, This is red color - any text...
3, Green, This is green color
  • Number of languages is unknown.
  • Table can have more than one localized field.
  • I use JPA with hibernate to access these tables.

How can I localize these codes and descriptions?


In opposition to the other answer:

I think, you should create a table that includes the locale as an extra field. This would enable you the build an index over the message id and locale to speed up searches. It would also make the administrative interface (I assume you have one, because otherwise you would use property files) easier to build, since you only have to work with one table and one object on the JPA side.

The table would look like this:

table messages
   id number,
   message_code number,
   locale string, // or number, depending on your app
   message1 string
   message2 string
   message3 string // or more/less

The message_code is not strictly neccessary, but help to reuse this table for different contexts.


think that localizations should be added vertically and not horizontally.

This means no a new column per language but a separated table for language name and identifier and another table with localized values in every possible language.

the table you have shown above is then the master table with the neutral language, in your case English, then the second table I mentioned above will have the same Ids (1,2,3...) for string id, then a column LanguageId and the LanguageText with the specific localized value for that LanguageId.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜