Copied to clipboard

Flag this post as spam?

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


  • Paul Marden 235 posts 338 karma points MVP c-trib
    Jul 16, 2009 @ 11:44
    Paul Marden
    0

    Accessing Dictionary Items

    I have a multilingual site which is somewhat of a hack, as it's a migration of an existing site to Umbraco.  E.g. I don't use hostnames to define language context.

    I've created the correct Languages in the Settings section (english and russian), and then created a Dictionary Item called Sector (there will be lots more later).  This has the correct English and Russian versions in it.

    I have a Macro which outputs an XML feed containing data in both English and Russian and I want to use the Dictionary to translate the word Sector for the English and Russian parts of the feed.

    The problem is that umbraco.library:GetDictionaryItem("Sector") returns the translated value for the current language context.  What I want to do is get to the dictionary and retrieve all current language values for an item -or- is there a method where I can pass the language context as a parameter, something like GetDictionaryItem("Sector", "EN") and GetDictionaryItem("Sector", "RS") rather than rely on the current context.

    Any ideas if this is possible or pointers to how I might go about writing this myself.

  • Ron Brouwer 273 posts 768 karma points
    Jul 16, 2009 @ 11:57
    Ron Brouwer
    1

    You could take a look at this: http://forum.umbraco.org/yaf_postst2208_Actionhandlers-and-dictionary-items--How-to-get-the-node-language-.aspx

    I seems like there is a Dictionary.DictionaryItem(Key).Value(domains[0].Language.id);

     

  • Paul Marden 235 posts 338 karma points MVP c-trib
    Jul 16, 2009 @ 17:08
    Paul Marden
    0

    Please no-one laugh at me for being thick.  I'm just a project manager pretending to be a developer!

    But I'm trying to add a bit of embedded c# at the bottom of one of my XSL files to make a call to Dictionary.DictionaryItem etc.

    I've done this before by plaigerising some of Doug's XSLSearch to put C# function's into my XSL so I thought I'd be able to do it for the Dictionary call, but it keeps erroring.  Here's my code

    <msxsl:script language="C#" implements-prefix="orcare">
        <![CDATA[
        public string GetDictionaryItemByContext(string key, int languageId)
        {
            return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(languageId);
        }
        ]]>
    </msxsl:script>

    But I get the following error:

    Error in XSLT at line 233, char 20
    231:       public string GetDictionaryItemByContext(string key, int languageId)
    232:       {
    233: >>>   return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(key).Value(languageId); <<<
    234:       }

    Anyone know what's going wrong?

  • Ron Brouwer 273 posts 768 karma points
    Jul 16, 2009 @ 18:04
    Ron Brouwer
    0

    try removing the "new" as it will try to create an instance of the string that is return by that function.

    If that won't work please share the entire xslt so I can test it myself

    Ron

  • Paul Marden 235 posts 338 karma points MVP c-trib
    Jul 20, 2009 @ 18:03
    Paul Marden
    0

    In the end I went with creating my own library based on this which Tim pointed to in an old post.  It's meant that I can now call a couple of functions one called GetDictionaryItemByLanguageId and one called GetDictionaryItemByCultureCode.

  • Andrei 2 posts 22 karma points
    Aug 17, 2011 @ 20:56
    Andrei
    0

    You can use something like this pair of overloaded functions:

    public static string GetDictionaryItemByCulture(string key, string cultureName)
    {
                return GetDictionaryItemByCulture(key, CultureInfo.GetCultureInfo(cultureName));
    }
    public static string GetDictionaryItemByCulture(string key, CultureInfo culture)
    {
                Language byCultureCode = Language.GetByCultureCode(culture.Name);
                return new Dictionary.DictionaryItem(key).Value(byCultureCode.id);
    }

    where cultureName is one of the list:

    http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.71%29.aspx

Please Sign in or register to post replies

Write your reply to:

Draft