When Sun was creating the internationalization framework for Java, I think it was before the invention of UTF-8 and there were hardly any UCS-2 text editors, so they required that .properties files be in ASCII format only with all non-ascii characters encoded with unicode escape codes.
It's a bit of a pain. For the most recent translations, I've been working with spreadsheets (I've made a new one for French below) and then use a script to generate the .properties files:
import codecs, string, sys
def main(argv):
global keywordList, objectList
if len(argv) < 2:
print """tsvToPo.py inputFilePrefix
"""
return
prefix = argv[1]
f = codecs.open(prefix + '.tsv', encoding='utf_8')
scanFile(f, 0)
f.close()
# Finished scanning files, so print out results
f = open('Keywords_' + prefix + '.properties', 'w')
outputAsJavaPropertyFile(f, keywordList)
f.close()
f = open('Objects_' + prefix + '.properties', 'w')
outputAsJavaPropertyFile(f, objectList)
f.close()
def scanFile(f, isScanForDefaults):
mode = 0
while 1:
line = f.readline()
if not line: break
splits = line.split('\t')
# Check for switches to different sections of the spreadsheet
firstCell = splits[0].strip()
if firstCell == 'Keywords':
mode = 1
continue
elif firstCell == 'Reserved words':
mode = 2
continue
elif firstCell == 'Objects':
mode = 3
continue
elif firstCell == 'Error Messages':
mode = 4
continue
# Pass control to the appropriate handler
if isScanForDefaults:
if len(firstCell) == 0: continue
english = firstCell.replace(' ', '_')
translated = english
else:
if len(firstCell) == 0: continue
if len(splits) < 2: continue
english = firstCell.replace(' ', '_')
translated = splits[1].strip()
if len(translated) == 0: continue
if mode == 0:
continue
elif mode == 1:
handleKeyword(english, translated)
elif mode == 2:
handleReservedWords(english, translated)
elif mode == 3:
handleObjects(english, translated)
def outputAsJavaPropertyFile(out, dict):
for (key, value) in dict.items():
out.write(escapeJavaPropertyString(key))
out.write(' = ')
out.write(escapeJavaPropertyString(value))
out.write('\n')
def escapeJavaPropertyString(str):
ascii = ''
for c in str:
code = ord(c)
if (code < 127):
ascii = ascii + c
else:
ascii = ascii + ('\u%04x' % code)
return ascii
def handleKeyword(english, translated):
global keywordList
if english in keywordList and len(keywordList[english]) > len(translated): return
keywordList[english] = translated
def handleReservedWords(english, translated):
global keywordList
if english in keywordList and len(keywordList[english]) > len(translated): return
keywordList[english] = translated
def handleObjects(english, translated):
global objectList
if english in objectList and len(objectList[english]) > len(translated): return
objectList[english] = translated
keywordList = {}
objectList = {}
main(sys.argv)
I've put in your changes. I'll ask around to some of my former French colleagues to see if they have alternate suggestions for how to handle throw/catch, and then I'll fix up the "lève" thing for throws.