This question has been flagged
1 Reply
3485 Views

I want to make a custom translation. Actually I want to show the (English source) of column E of the translations csv plus the translated term (column F) together. In my case it is a combination of English and Chinese so practically I want to see "Sales 销售“ for the 'Sales' Module for example

I have a python script that should do that (combining column E and column F of the Chinese language .csv) that looks like this

import csv
import sys

filename = sys.argv[1]

with open(filename, 'rb') as f:
    rows = list(csv.reader(f))
    for row in rows:
        if row[4] != row[5]:
            row[5] = ' '.join((row[4], row[5]))
            #print row[5]

with open('chinese_english_combined.csv', 'wb') as f:
    writer = csv.writer(f)
    writer.writerows(rows)

this worked with an older v7 but now trying to combine languages in v8 I get an error

Traceback (most recent call last):
  File "combineLanguages.py", line 9, in <module>
    if row[4] != row[5]:
IndexError: list index out of range

 

EDIT: I did not write the script myself and I don't know python, that's why I'm asking here

 

Avatar
Discard
Best Answer

"List index out of range" means that either column 5 or 6 (the counting starts at 0 for the first column) is not filled in correctly, or might even be missing. Make sure that the csv file you are feeding your script is exactly equal to the one you use in verison 7. That means that it should have the exact same columns, in the exact same order and has at least one row.

 

If you can confirm that is the case, make sure the 5th and 6th columns at least contain some value.

Avatar
Discard
Author

I though it must be something similar to that. It's a little confusing that python uses the term 'row' when it actually means 'column'. Nevertheless, the file structure is the same and both (column 4 & 5) contain data. Can it be I need to remove the 'header'. Will check that out and report back. By the way: the script doesn't work with the 'old' v7 file neither anymore

"By the way: the script doesn't work with the 'old' v7 file neither anymore". Check the encoding of your .csv file, it shouldn't unicode as the parser doesn't support it.

Author

using "Chinese Simplified" encoding helped with the error message, thanks. Now I see that something is not working with the commas (as if there where too many of them in the translated terms) in the csv file. I have in total 6 columns (the last being the translated term) but when I open the combined translation that is being made by my script now, so of the terms have many more columns. By default my openoffice gives me the option using "," & ";" for separating things (and when I choose anything else the preview just shows one single column). I guess I have to fix these terms handish or is there any suggestion regarding this from you end?