To import csv there’s only one function: system.dataset.fromCSV, which requires csv format from .toCSV.
But that file doesn’t have Russian text, but only ???..
So, how can I export and import Russian texts?
And this my working script (on buttons actionPerformed):
import csv
def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs)
for row in csv_reader:
yield [unicode(cell, 'utf-8') for cell in row]
parent = event.source.parent
locale = parent.getComponent('Dropdown').selectedStringValue
file = system.file.openFile("csv")
if file != None:
csvData = unicode_csv_reader(open(file))
header = csvData.next()
dataset = system.dataset.toDataSet(header ,list(csvData))
dsLocale = system.dataset.getColumnHeaders(dataset)[1]
if dsLocale != locale:
system.gui.messageBox("locale of CSV (%s) doesn't match selected locale (%s). Aborting." % (dsLocale, locale))
else:
oldData = parent.getComponent('Table').data
parent.getComponent('Table').data = dataset
if system.gui.confirm("Is data correct for locale %s?\nThis will override any existing translations" % locale):
pyDs = system.dataset.toPyDataSet(dataset)
for row in pyDs:
term = row[0]
newValue = row[1] or None
#print "term, newValue= ", term,newValue
system.util.modifyTranslation(term, newValue, locale)
else:
parent.getComponent('Table').data = oldData
If you have a lot of lines in your .csv file (mine have more than 5200) it’ll take a while and block Ignition thread.
So, system.util.invokeAsynchronous with system.util.invokeLater must be used not to block the Vision thread and show the user some progress feedback…