Multilanguage Support

5 posts, 0 answers
  1. Nikolai Hellwig
    Nikolai Hellwig avatar
    16 posts
    Member since:
    Mar 2010

    Posted 26 May 2010 Link to this post

    Hi,

    let's assume we have 2 tables:

    Table a:    (ID, Address, Desc ID)
    Table b:    (Desc ID, Language, Text)

    Is there a way to directly access the text field with the current language. Something like:

    a.CurrentText

    instead of 

    a.b.where(f => f.Language.Equals(CurrentLanguage)).Single().Text

    Best Regards
    Nikolai Hellwig
  2. Serge
    Admin
    Serge avatar
    375 posts

    Posted 27 May 2010 Link to this post

    Hello Nikolai Hellwig,

     Given that it is a collection that you are accessing there is no shortcut. What you can do however is to skip the where clause. You can write it like this : 

    a.b.Single(f => f.Language.Equals(CurrentLanguage)).Text

    Also you might want to consider using SingleOrDefault as it will not throw an exception if there is no such item or more than one.


    All the best,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. Nikolai Hellwig
    Nikolai Hellwig avatar
    16 posts
    Member since:
    Mar 2010

    Posted 27 May 2010 Link to this post

    this is not exactly what i wanted, but thank you for your help.
    what i have just done is: extending each class in a partial class with an property which links to the current language record in the text-table.

    so i can access with:  a.b.Text

    the problem is that openaccess fires 2 sql commands. i will try using fetchgroups soon. maybe this can help.

    best regards
    nikolai
  5. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 28 May 2010 Link to this post

    Hi Nikolai,

    I have done it in almost the same way. I have included a GetText(language) on the class to get me the text in the right language..That way you can let other (outside) logic decide what the current language is.
    I have included the list of texts (in all supported languages) in the default fetch group (of the owning class)... It didn't yield any performance hit...actually it performs better because texts in all languages are fetched at once instead of searching through the list (and thus issuing a SQL statement) to find the right one to return.

    Another solution I could think of is to store the texts in a Dictionary<string, string> where the first is the language code and the second is the actual text in that language... Might perform better if you're supporting many languages.

    In my case I only had 3 and I guessed that it was a bit overkill to go for the Dictionary...

    Regards

    Henrik
  6. Serge
    Admin
    Serge avatar
    375 posts

    Posted 28 May 2010 Link to this post

    Hello Nikolai Hellwig,

    Indeed you are on the right track. Using Fetch Plans will result in Telerik OpenAccess ORM not firing 2 queries. Keep in mind that if you have a long lasting scope and you have already fetched an object, it will not be fetched again from the database.

    If it is not a case when you absolutely need to be as fast as you can I would suggest not worrying about the second query. 

    If you need something else feel free to contact us back.

    Have a great day,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner