当前位置: 动力学知识库 > 问答 > 编程问答 >

bidirectional text, converting from unicode to ascii on python

问题描述:

I am trying to write a feature involving translating multilingual text, with bidirectional problems (i.e English words within a Hebrew sentence)

When ordering the text in the right way (after translating), we need to convert it to ascii (regular python str), to use the push notification services of apple and google.

The problem is when converting from unicode to ascii, the string is unordered (the words themselves, not the internal chars order inside the words).

is there a way making sure, that the conversion (unicode -> ascii) will result the proper word ordering?

for instance

str1 ='Group1 \xd7\x94\xd7\xa6\xd7\x98\xd7\xa8\xd7\xa3 \xd7\x9c zlatan'

str2 =' \xd7\xa9\xd7\x9c\xd7\x97 \xd7\x94\xd7\x95\xd7\x93\xd7\xa2\xd7\x94'

print str1

print str2

print str2 + '.' + str1

the console output will be:

Group1 zlatan


.zlatan Group1 .

as you can see the words 'Group1' and 'zlatan' got switched, as well as the sentences order

cheers,

分享给朋友:
您可能感兴趣的文章:
随机阅读: