Skip to content

Instantly share code, notes, and snippets.

@daegalus
Created March 4, 2013 18:37
Show Gist options
  • Save daegalus/5084355 to your computer and use it in GitHub Desktop.
Save daegalus/5084355 to your computer and use it in GitHub Desktop.
Parser for HAL translation Excel file to Spring Property Files.
from xlrd import open_workbook,cellname
import os
# Open the Excel Spreadsheet and get the first Sheet
book = open_workbook('translations.xls')
sheet = book.sheet_by_index(0)
# Setup initial lists for storing the keys and langauges
keys = []
languages = []
# Iterate through the columns and save them to the lists. If its the first column, save it into Keys, otherwise append the list from columns to the language list.
# It will become a List of Lists
for col_index in range(sheet.ncols):
if(col_index == 0):
keys = sheet.col(col_index)
else:
languages.append(sheet.col(col_index))
# Make sure the folder exists, and create it if it doesn't
path = os.path.join(".","properties")
if not os.path.exists(path):
os.makedirs(path);
position = 0;
# Iterate through the list of language lists.
for language_set in languages:
# Get each value from the list
for value in language_set:
current_index = language_set.index(value)
# If the item is the first item in the list, it is the name of the language. Use it to create the properties file.
# Otherwise, write into that file the key/value pairs using the Keys list we created before.
if current_index == 0:
file = open(os.path.join(path, language_set[position].value+".properties"), encoding='utf-8', mode='w')
else:
file.write("%s=%s\n" % (keys[current_index].value, value.value))
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment