Nice to hear you are looking into the translation manager!
an example of the CSV:
Key,es,zh,en,nl
Menu Item 2,Elemento de Menú 2,菜单项 二,Menu Item 2,Menu Item 2
Dutch,Holandés,荷兰语,Dutch,Nederlands
So if i want to add another language i just put the language code after the last in the header and then adjust it, but that works easily in Excel for example.
My script to export CSV:
def runAction(self, event):
import csv
from com.inductiveautomation.ignition.gateway import IgnitionGateway
# Get the localization manager
localization_manager = IgnitionGateway.get().getLocalizationManager()
# Load the full translation package
translation_package = localization_manager.loadFullPackage()
# Get all translation keys
keys = translation_package.getAvailableKeys()
# Collect all available languages
all_languages = set()
for key in keys:
translations = translation_package.getTranslationsFor(key)
all_languages.update(translations.keys())
# Define the CSV file path
csv_file_path = "filepath"
# Write to CSV
with open(csv_file_path, mode='w') as file:
writer = csv.writer(file, lineterminator='\n')
# Create header row
header = ["Key"] + list(all_languages)
writer.writerow(header)
# Write translation rows
for key in keys:
translations = translation_package.getTranslationsFor(key)
row = [key] + [translations.get(lang, '') for lang in all_languages]
writer.writerow(row)
print("Export successful!")
And import back to the translationmanager:
import system.util
import io
# Define the CSV file path
csv_file_path = "filepath"
# Read from CSV and update translations
with io.open(csv_file_path, mode='r', encoding='utf-8-sig') as file:
# Read all lines
lines = file.readlines()
# Split the lines into headers and rows
headers = lines[0].strip().split(',')
system.perspective.print("CSV Headers: " + str(headers))
if 'Key' not in headers:
system.perspective.print("Error: 'Key' column not found in CSV file.")
return
languages = headers[1:] # Get languages from the header row
system.perspective.print("Languages found: " + str(languages))
for line in lines[1:]:
try:
row = line.strip().split(',')
key = row[headers.index('Key')]
translations = {lang: row[headers.index(lang)] for lang in languages if row[headers.index(lang)]}
for lang, translation in translations.items():
try:
system.util.modifyTranslation(key, translation, lang)
except Exception as e:
system.perspective.print("Error adding translation for {key} in {lang}: {e}")
except Exception as e:
system.perspective.print("Error processing row: {e}")
system.perspective.print("Import successful!")
*I am not an expert in Ignition, but this works as expected