3 Replies Latest reply on Mar 13, 2010 5:50 PM by Vasilii Lukoyanov

    Localized content in database

    Florian Petersen Newbie

      Hi there,


      maybe this is a very common problem, but i didn't find about this here and in web... I am currently writing an application that should be used to read and write content of different languages from/into the database.
      I know i could add a new column to the relevant tables and add a new property to the relevant entities but i don't really want to extend the entities for every new language i add...
      So do you have an idea for this, e.g. is there any kind of dynamic column selection for an entity property? And what is search behaviour in this case?
      I am using Seam 2.2.0 with Hibernate as JPA Provider and Hibernate Search.


      Thanks a lot, best regards
      Flo

        • 1. Re: Localized content in database
          Ronald van Kuijk Apprentice

          Why not add a lang column to the entities... would not need to change anything if a new language is added? Or do I miss something?

          • 2. Re: Localized content in database
            Florian Petersen Newbie

            Hi Ronald,


            first thanx for the response. Of course that would work somehow but i think would cause database and index overhead as every entity (with all property values, which are mostly the same) had to be saved n times, once for every language, isn't it?
            I know a way to avoid this would perhaps be to separate the non-localized properties from the localized (putting them in an extra table), but for this to work i had to define new entities and establish some kind of one-to-many relationship between the original entity and the entity containing the localized properties, right?
            Hmmm, also not that stylish...
            But maybe i am just a blockhead this time?!?


            Thanks, best regards
            Flo

            • 3. Re: Localized content in database
              Vasilii Lukoyanov Newbie

              I can try the following solution:


              Add new entity to represent localized strings with the following fields



              localizedText {
                  long id,
                  int lang_id,
                  varchar text,
                  primary key (id, lang_id)
              }




              When you create new multi-lang entity, create new N LocalizedText instances to represent N languages for every multi-lang field. Then you just put those LocalizedText.id instead of actual text.


              In order to transparently convert id to text, you can implement custom hibernate interceptor.


              The main disadvantage of this approach complicated entity update operation.


              ----------

              Free templates for websites