translate, language, translation-6089103.jpg

Translate Texts in Tableau Workbook

As I delved into potential project ideas, I stumbled upon a suggestion within the Tableau community—an envisioned feature that allows text translation in Tableau workbooks across different languages. Realizing that one of my colleagues shared this perspective, it motivated me to create a tool. This tool empowers users to input a Tableau Workbook, seamlessly executing translations on the fly and generating the translated Tableau Workbook without altering any other elements.

When you open the Tableau Workbook (.TWB) file in a text editor, you’ll find that it’s essentially an XML file. XML files use tags to define the structure of a document and how information should be stored and transmitted over the internet. This concept applies to the Tableau Workbook as well. Various elements like dashboards, sheets, dashboard actions, parameters, sets, etc., are organized using specific tags, and detailed information is stored within these tags.

A Tableau Workbook (.TWB) is an XML file. Unpacking a packaged Tableau workbook, akin to unzipping a file, reveals a folder containing the Tableau Workbook, its data source, and images in their respective folders.

All the text in the Tableau Workbook is stored within the nested <run></run> tags of the <formatted-text></formatted-text>. Using the ElementTree XML library in Python, we can extract the relevant contents of these <run></run> tags to create a list of texts that need translation. This library allows us to efficiently parse XML file. For free text translation, we can import the ‘Translators’ library.

While the ElementTree.write() method allows for the direct modification of XML file attributes, I’ve observed that when using this method to output the XML, sets or dashboard actions referenced in the workbook become disordered, leading to disruptions in some of the intended interactions.

I addressed the problem by reading and writing the file line by line. If a line with a run tag includes the target text, I replace it with the corresponding translation. It’s important to note that we should ensure the file is read with UTF-8 encoding; otherwise, some special symbols used for references might be omitted when writing the file.

This image illustrates the logic flow of the Python code I’ve written.

You can find this project in my Github.

Leave a Comment

Your email address will not be published. Required fields are marked *