def separate_qtranslate_content(text):
 qt_start = u'<!--:'
 qt_end = u'-->'
 qt_end_with_lang_len = 5
 qt_chunks = text.split(qt_start)
 content_by_lang = {}
 common_txt_list = []
 for c in qt_chunks:
  if (not c.strip()):
   continue
  if c.startswith(qt_end):
   lang = u''
   c = c.lstrip(qt_end)
   if (not c):
    continue
  elif c[2:].startswith(qt_end):
   lang = c[:2]
   c = c[qt_end_with_lang_len:]
  else:
   lang = u''
  if (not lang):
   common_txt_list.append(c)
   for l in content_by_lang.keys():
    content_by_lang[l].append(c)
  else:
   content_by_lang[lang] = (content_by_lang.get(lang, common_txt_list) + [c])
 if (common_txt_list and (not content_by_lang)):
  content_by_lang[u''] = common_txt_list
 for l in content_by_lang.keys():
  content_by_lang[l] = u' '.join(content_by_lang[l])
 return content_by_lang

def separate_qtranslate_content ( text ) : qt_start = u'<!--:' qt_end = u'-->' qt_end_with_lang_len = 5 qt_chunks = text . split ( qt_start ) content_by_lang = { } common_txt_list = [ ] for c in qt_chunks : if ( not c . strip ( ) ) : continue if c . startswith ( qt_end ) : lang = u'' c = c . lstrip ( qt_end ) if ( not c ) : continue elif c [ 2 : ] . startswith ( qt_end ) : lang = c [ : 2 ] c = c [ qt_end_with_lang_len : ] else : lang = u'' if ( not lang ) : common_txt_list . append ( c ) for l in content_by_lang . keys ( ) : content_by_lang [ l ] . append ( c ) else : content_by_lang [ lang ] = ( content_by_lang . get ( lang , common_txt_list ) + [ c ] ) if ( common_txt_list and ( not content_by_lang ) ) : content_by_lang [ u'' ] = common_txt_list for l in content_by_lang . keys ( ) : content_by_lang [ l ] = u' ' . join ( content_by_lang [ l ] ) return content_by_lang
parse the content of a wordpress post or page and separate qtranslate languages .