Question
· Oct 12, 2021

Localize Text in an XData Block

Hi everyone!

I am trying to localize text in an XData block using the $$$Text macro. A snippet of code is included below. Is there an easy way to localize the text included in an XData block? So far, using the $$$Text macro is not working; when I export the %MessageDictionary, the text to be localized isn't included in the export.

 

XData LocalizedEmail [ MimeType = text/html ]
{
<body>

<p>

Text to be translated into another language

</p>

</body>

}

Thank you in advance!

Product version: IRIS 2020.3
Discussion (3)1
Log in or sign up to continue

Hi Erica,

$$$Text generates content into the message globals at compile time. Here's one way to solve the problem:

Class Erica.DemoLocalizedXData
{

Parameter DOMAIN = "Demo";

XData LocalizedEmail [ MimeType = text/html ]
{
<body>
<p>
Text to be translated into another language
</p>
</body>
}

ClassMethod GetLocalizedContent(xDataName As %String) As %String [ CodeMode = objectgenerator ]
{
    do %code.WriteLine(" Quit $Case(xDataName,")
    set key = ""
    for {
        set xdata = %class.XDatas.GetNext(.key)
        quit:key=""
        set data = xdata.Data.Read() // Assumptions about length here...
        do %code.WriteLine("   "_$$$QUOTE(xdata.Name)_":$$$Text("_$$Quote^%qcr(data)_"),")
    }
    do %code.WriteLine("   :"""")")
}

}

After compilation you'll have:

^IRIS.Msg("Demo")="en"
^IRIS.Msg("Demo","en",3630108798)="<body>"_$c(13,10)_"<p>"_$c(13,10)_"Text to be translated into another language"_$c(13,10)_"</p>"_$c(13,10)_"</body>"_$c(13,10)

If you want to localize individual strings in the XData block independent of the HTML markup that gets a little more complicated. I'd think it's simpler/possibly better to localize the entire block at once though.