Tag Archives: XML

Drilling for Translatable Content

I’ve been spending a lot of time with XML content recently.

In one case I received content where there are XML elements which have translatable attributes. Within this translatable attribute text are custom placeholder tags which in turn have translatable attributes.

<cust-ele att="needs-translation" value="Here is text with [proprietary att='I also require translation' dnt="77yf990"] placeholders contained within."/>

Borrowing from XLIFF, my current approach is to markup like so:

<cust-ele att="needs-translation" value=""><trans-att id="765fe3">Here is text with <ph id="432ab">[proprietary att='<sub>I also require translation</sub> dnt="77yf990"]</ph> placeholders contained within.</trans-att></cust-ele>

Is anyone else seeing this madness?


eXtensively Maddening Language

After spending a very long day with the System.Xml and System.Xml.Linq namespaces I now understand why the Expando object and JSON were invented!

What I wanted to achieve was quite simple – I thought: read an existing XLIFF file from top to bottom looking for any trans-units, process those in some way, write the modified versions back into the XLIFF and leave everything else as it was.

The plan: use an XmlTextReader and XmlTextWriter in unison. This approach would utilise streaming and thus deal with large files.

It turns out that if you have multiple namespaces in your files this gets messy quickly, particularly if you construct modified portions of the XML as isolated fragments and then try to integrate them again. I was ending up with all kinds of locally declared namespaces though at the end of the day’s work I figured this could have been because I was looking at the non-reintegrated fragments. Perhaps if I’d been more patient and waited until I had a final integrated document they would have all been resolved correctly. Also, the methods on XmlTextReader and XmlTextWriter means you end up with very verbose code.

My final implementation used XmlTextReader for reading the existing file and then XDocument and Linq to build and write out the modified version. Linq to XML is just so elegant.

Trying to build simple namespace declarations and enforcement of prefix usage in the main file seemed overly difficult with both Sytsem.Xml and Linq.