Python converting strings to dictionary -


i have task. convert .po msgid , msgstr dictionary. parsed , got something, this

cancel anuluj close zamknij continue kontynuuj 

now need dictionary. example, first line mean english, second translations. part of code

mess = {} mess[string.replace(string.replace(native_language, '\\"', '"'), '\\n', '\n')] = string.replace(string.replace(translation_language, '\\"', '"'), '\\n', '\n')

everything ok. problem in last couple of strings. example. have not written couple of continue kontynuuj. think have problem in \n. ? can me ?

full text of script:

source = '/var/www/pl.po' target = '/var/www/mess.json' file = open(source, 'rb')  = 0 isignore = false issrc = false lang = '' native_language = '' translation_language = '' mess = {}  str in file:     += 1     if < 15:         str = str.strip()         if str[0:10] == '"language:':             lang = str[11:13]         continue      str = str.strip()     if str[:5] == 'msgid':         if len(native_language) > 0:         mess[string.replace(string.replace(native_language, '\\"', '"'), '\\n', '\n')] = string.replace(string.replace(translation_language, '\\"', '"'), '\\n', '\n')         if str != 'msgid ""' , isignore == false:             native_language = str[7:-1]         else:             native_language = ''             translation_language = ''             issrc = not isignore      elif str[:6] == 'msgstr':         if str != 'msgstr ""':             translation_language = str[8:-1]         isignore = false         issrc = false file.close()  file = open(target, 'w')  keys = mess.keys() keys.sort()  key in keys:     file.write(',"' + key + '":["' + mess[key] + '"]') file.close() 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -