Question
Erica Ford · Oct 12

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
00
2 0 3 88
Log in or sign up to continue

If the string variable 'stra' contains the XData bloc.

$E(stra,$F(stra,"<p>"),$F(stra,"</p>")-5)

The tags '<p>' and '</p>' must be in lowercase.

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.

One note here, $$Quote^%qcr will represent control characters with $c(decimalAsciiCode) syntax - like the newlines in this case. I think there's some more official classmethod that's equivalent, but I don't recall where it is off the top of my head.