2025-11-06 1:52 AM - edited 2025-11-06 1:53 AM
I have four languagese/translation with their translations in TouchGFX Designer
Is there a way to reorder them? I would like to have IT GB ESP FR
Solved! Go to Solution.
2025-11-07 12:53 AM
Yes, that was the solution.
A simple Python script that reorders the texts.xml according to my necessity works just fine. The Designer picks up the updated texts.xml file with the new ordering.
Below is the code if someone needs it in the future.
import xml.etree.ElementTree as ET
from xml.dom import minidom
def reorder_languages(input_file, output_file):
"""
Reorders languages and translations from GB, IT, FR, ESP to IT, GB, ESP, FR
"""
# Define the new order
new_order = ['IT', 'GB', 'ESP', 'FR']
# Parse the XML file
tree = ET.parse(input_file)
root = tree.getroot()
# Find and reorder Languages section
languages = root.find('Languages')
if languages is not None:
# Get all Language elements
lang_elements = list(languages.findall('Language'))
# Create a dictionary for easy lookup
lang_dict = {elem.get('Id'): elem for elem in lang_elements}
# Clear existing languages
languages.clear()
# Add languages in new order
for lang_id in new_order:
if lang_id in lang_dict:
languages.append(lang_dict[lang_id])
# Find and reorder Translations in all Text elements
texts = root.find('Texts')
if texts is not None:
for text_group in texts.findall('.//TextGroup'):
for text in text_group.findall('Text'):
# Get all Translation elements
translations = list(text.findall('Translation'))
# Create a dictionary for easy lookup
trans_dict = {elem.get('Language'): elem for elem in translations}
# Clear existing translations
for trans in translations:
text.remove(trans)
# Add translations in new order
for lang_id in new_order:
if lang_id in trans_dict:
text.append(trans_dict[lang_id])
# Convert to string with proper formatting
xml_str = ET.tostring(root, encoding='utf-8')
# Pretty print
dom = minidom.parseString(xml_str)
pretty_xml = dom.toprettyxml(indent=" ", encoding='utf-8')
# Remove extra blank lines
lines = pretty_xml.decode('utf-8').split('\n')
lines = [line for line in lines if line.strip()]
# Write to output file
with open(output_file, 'w', encoding='utf-8') as f:
f.write('\n'.join(lines))
print(f"Successfully reordered languages in {output_file}")
print(f"New order: {' -> '.join(new_order)}")
if __name__ == "__main__":
# Usage
input_file = "texts.xml"
output_file = "output.xml" # Change to your desired output file name
reorder_languages(input_file, output_file)
2025-11-06 2:23 AM - edited 2025-11-06 5:45 AM
It doesn't seem to be an option to do that (correct me if I'm wrong), but, because the text file is just an XML, a simple Python script that reorders, according to your input, the sequence of the languages is a solution.
2025-11-06 4:07 AM
By right-clicking on the column, you can both rename and delete the column:
The only constraint is that you cannot have two columns of the same name.
2025-11-06 5:01 AM
If I'm understanding right, this would just rename the column. If I already have content in the column (so translations), it won't change accordingly
I need to reorder the translations, not just rename the column
Or, am I understanding incorrectly?
2025-11-06 5:33 AM
It is true that there is no user interface way of doing this. My testing shows that reordering in texts.xml does change the order of the columns in the user interface.
Why is the order in the interface so important to you?
2025-11-06 5:44 AM
Visualization purpose when scanning the array of languages. I could remap them in code, but it would add more useless headroom.
2025-11-06 6:02 AM
I see.
Have you tried reordering texts.xml and seeing if that reorders them in Designer as well? That seems to be the case on my side.
2025-11-07 12:53 AM
Yes, that was the solution.
A simple Python script that reorders the texts.xml according to my necessity works just fine. The Designer picks up the updated texts.xml file with the new ordering.
Below is the code if someone needs it in the future.
import xml.etree.ElementTree as ET
from xml.dom import minidom
def reorder_languages(input_file, output_file):
"""
Reorders languages and translations from GB, IT, FR, ESP to IT, GB, ESP, FR
"""
# Define the new order
new_order = ['IT', 'GB', 'ESP', 'FR']
# Parse the XML file
tree = ET.parse(input_file)
root = tree.getroot()
# Find and reorder Languages section
languages = root.find('Languages')
if languages is not None:
# Get all Language elements
lang_elements = list(languages.findall('Language'))
# Create a dictionary for easy lookup
lang_dict = {elem.get('Id'): elem for elem in lang_elements}
# Clear existing languages
languages.clear()
# Add languages in new order
for lang_id in new_order:
if lang_id in lang_dict:
languages.append(lang_dict[lang_id])
# Find and reorder Translations in all Text elements
texts = root.find('Texts')
if texts is not None:
for text_group in texts.findall('.//TextGroup'):
for text in text_group.findall('Text'):
# Get all Translation elements
translations = list(text.findall('Translation'))
# Create a dictionary for easy lookup
trans_dict = {elem.get('Language'): elem for elem in translations}
# Clear existing translations
for trans in translations:
text.remove(trans)
# Add translations in new order
for lang_id in new_order:
if lang_id in trans_dict:
text.append(trans_dict[lang_id])
# Convert to string with proper formatting
xml_str = ET.tostring(root, encoding='utf-8')
# Pretty print
dom = minidom.parseString(xml_str)
pretty_xml = dom.toprettyxml(indent=" ", encoding='utf-8')
# Remove extra blank lines
lines = pretty_xml.decode('utf-8').split('\n')
lines = [line for line in lines if line.strip()]
# Write to output file
with open(output_file, 'w', encoding='utf-8') as f:
f.write('\n'.join(lines))
print(f"Successfully reordered languages in {output_file}")
print(f"New order: {' -> '.join(new_order)}")
if __name__ == "__main__":
# Usage
input_file = "texts.xml"
output_file = "output.xml" # Change to your desired output file name
reorder_languages(input_file, output_file)