Copied to clipboard

Flag this post as spam?

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


  • Ivan 165 posts 543 karma points
    Sep 30, 2012 @ 16:41
    Ivan
    0

    Is it possible to use Dictionary item from within RTE?

    Hi guys.

    If so, please, suggest corresponding syntax.

     

    PS.

    That's for translation purposes.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Sep 30, 2012 @ 18:42
    Jan Skovgaard
    0

    Hi Ivan

    In short the answer is no.

    The only way you can add text that uses dictionary items into RTE is by using a macro.

    Could you perhaps try to describe your scenario and why you would need to be able to use dictionary items within the RTE field?

    Looking forward to hearing from you.

    /Jan

  • Ivan 165 posts 543 karma points
    Sep 30, 2012 @ 19:39
    Ivan
    0

    Thanks for the answer, Jan.

    I was inteded to translate text on the sidebar blocks.

  • Mike Chambers 635 posts 1252 karma points c-trib
    Oct 01, 2012 @ 10:31
    Mike Chambers
    0

    there is another way... rather than individual macros in the RTE you can replace your <umbraco:Item field="contents" runat="server" /> (or whatever your rte content param is) with a macro that replaces tokens in that content.

    You need to remember to grab the rte content and render any macros already in it using the umbraco.library.RenderMacroContent(String, NodeId); if you do already use macros in the content.

    we went with {#XXXX} to keep consistent with the shorthand for dictionary items elsewhere.

    something like the below in a usercontrol macro worked for us.

    #region replace any dictionary items
                try
                {
                    Regex regDictionaryItem = new Regex(@"{#([^}]*)}", RegexOptions.IgnoreCase);
                    MatchCollection ms = regDictionaryItem.Matches(umbraco.library.StripHtml(doc.InnerXml));
    
                    foreach (Match match in ms)
                    {
    
                        try
                        {
                            // make replacements in the content xml text nodes only, for any matching definition term
                            // get all text nodes (reset as the previous lookup may have generated more textnodes)
                            // filter to what we are looking for allow for upper and lower as xpath is case-sensitive
                            // NB this might have false matches as not looking for words, but does filter in the right direction
    
                            doc.DocumentElement.SetAttribute("searchAttribute0", match.Groups[0].Value);
                            XmlNodeList textNodes = doc.SelectNodes("//text() [contains(.,//@searchAttribute0)]");
    
                            for (var i = 0; i < textNodes.Count; i++)
                            {
                                //loop throught the matched textnodes to replace on a word matching basis
                                textNodes[i].InnerText = textNodes[i].InnerText.Replace(match.Groups[0].Value, umbraco.library.GetDictionaryItem(match.Groups[1].Value));
                            }
                        }
                        catch
                        {
                            UmbracoJPT.Utils.Files.WriteToLogFile("error", @"DICTIONARYITEM ERROR" + match.Groups[0].Value + @"
    ", true); } } } catch { } #endregion
Please Sign in or register to post replies

Write your reply to:

Draft