Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chizzl 36 posts 107 karma points
    Aug 14, 2011 @ 11:08
    Chizzl
    0

    DictionaryItem by Culture

     

    Hi,

    I have a site in 3 languages. The Culture is set when the language changes.

    e.g.

    System.Threading.Thread.CurrentThread.CurrentCulture new CultureInfo("fr-FR");

    I've created a macro "GetCultureInfo" with the following code to check the Culture update;

    @using System.Globalization;
    <strong>Current culture :</strong> @CultureInfo.CurrentCulture.DisplayName<br/>
    <strong>Native Name :</strong> @CultureInfo.CurrentCulture.NativeName

    When I add the macro to my template and use the language switcher, I always get the culture as expected.

    But when I use a dictionary item to retrieve a translation for some static text, I only get the English value.

    <umbraco:Macro Alias="GetCultureInfo" runat="server"></umbraco:Macro>
    <umbraco:Macro runat="server" language="cshtml">
        @Dictionary["Log In"]
    </umbraco:Macro>

    Any idea why the dictionary item is not taking the value based on the current culture or how to fix this?

    Thanks for the help...

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 14, 2011 @ 14:15
    Dirk De Grave
    0

    Chizzi,

    I'm not sure why it doesn't work when you've explicitely set the culture, but there's a better solution to this. If you've got a site in multiple languages, make sure to set hostnames for each of the language sites and set the appropriate culture. Doing so will make sure that each call to GetDictionaryItem("key") will get the correct translation.

    If you only have a single domain, but need three different language sites and want to use the above technique for fetching the dictionary items, so your content structure looks similar to this below:

    -Content
    --Site
    ---nl
    ---fr
    ---en

    In this case, set a dummy hostname on the nl node (hostname: nl, culture nl-BE or nl-NL). Can do the same for fr and en node.

     

    Hope this helps.

    Regards,

    /Dirk

     

     

  • Chizzl 36 posts 107 karma points
    Aug 14, 2011 @ 14:15
    Chizzl
    0

    Hi Dirk,

    I preferred not to work with different hostnames for this project.

    But with a little trail and error, I've found that I have to set the CurrentUICulture for the dictionaryitems.

    So at the language switch I set both now;

    System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); 
    System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");

    But thanks for your info anyway.

Please Sign in or register to post replies

Write your reply to:

Draft