Actionhandlers and dictionary items - How to get the node language ? Options
tim
Posted: Wednesday, December 19, 2007 1:38:53 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
Hi,

I'm trying to get the contents of a dictionary item from inside an actionhandler.

But how can I get the node language ? And what do I need to do to make it fetch the right culture contents ?

Thanks

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
tim
Posted: Wednesday, December 19, 2007 2:02:44 PM

Rank: Addict

Joined: 2/19/2007
Posts: 738
Location: Belgium
I took a look at the source code and managed to make it work.

This is the code for the umbraco.library.GetDictionaryItem

But when you want to use this in an actionhandler it doesn't work.

HttpContext.Current.Items["pageID"]

Code:


public static string GetDictionaryItem(string Key)
        {
            try
            {
                string pageId = HttpContext.Current.Items["pageID"] as string;
                Domain[] domains = GetCurrentDomains(int.Parse(pageId));
                if (domains != null)
                {
                    if (domains.Length > -1)
                    {
                        return new Dictionary.DictionaryItem(Key).Value(domains[0].Language.id);
                    }
                }

                return new Dictionary.DictionaryItem(Key).Value();
            }
            catch (Exception errDictionary)
            {
                HttpContext.Current.Trace.Warn("library", "Error outputting dictionary item '" + Key + "'",
                                               errDictionary);
                return string.Empty;
            }
        }



So to have a version working an an actionhandler you need to pass the documentobjectid.

Code:


public string GetDictionaryItem(string Key, int id)
        {
            try
            {
                string pageId = id.ToString();
                Domain[] domains =  umbraco.library.GetCurrentDomains(int.Parse(pageId));
                if (domains != null)
                {
                    if (domains.Length > -1)
                    {
                        return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(Key).Value(domains[0].Language.id);
                    }
                }


                return new umbraco.cms.businesslogic.Dictionary.DictionaryItem(Key).Value();
            }
            catch (Exception errDictionary)
            {
                HttpContext.Current.Trace.Warn("library", "Error outputting dictionary item '" + Key + "'",
                                               errDictionary);
                return string.Empty;
            }
        }


So in the actionhandler I just do:

GetDictionaryItem("MailAdminPublish",documentObject.Id);



Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.