only deal with unicode
This commit is contained in:
parent
8961b8b7b7
commit
6fea97bd2a
2 changed files with 29 additions and 29 deletions
|
@ -204,7 +204,7 @@ def codeToLang(code):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def langTo3Code(lang):
|
def langTo3Code(lang):
|
||||||
lang = englishName(lang)
|
lang = langEnglishName(lang)
|
||||||
if lang:
|
if lang:
|
||||||
lang=lang.lower()
|
lang=lang.lower()
|
||||||
for l in _iso639_languages:
|
for l in _iso639_languages:
|
||||||
|
@ -213,7 +213,7 @@ def langTo3Code(lang):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def langTo2Code(lang):
|
def langTo2Code(lang):
|
||||||
lang = englishName(lang)
|
lang = langEnglishName(lang)
|
||||||
if lang:
|
if lang:
|
||||||
lang=lang.lower()
|
lang=lang.lower()
|
||||||
for l in _iso639_languages:
|
for l in _iso639_languages:
|
||||||
|
|
|
@ -65,10 +65,10 @@ def wrap(text, width):
|
||||||
|
|
||||||
def wrapString(string, length=80, separator='\n', balance=False):
|
def wrapString(string, length=80, separator='\n', balance=False):
|
||||||
'''
|
'''
|
||||||
>>> wrapString("Anticonstitutionellement, Paris s'eveille", 16)
|
>>> wrapString(u"Anticonstitutionellement, Paris s'eveille", 16)
|
||||||
"Anticonstitution\nellement, Paris \ns'eveille"
|
u"Anticonstitution\\nellement, Paris \\ns'eveille"
|
||||||
>>> wrapString('All you can eat', 12, '\n', True)
|
>>> wrapString(u'All you can eat', 12, '\\n', True)
|
||||||
'All you \ncan eat'
|
u'All you \\ncan eat'
|
||||||
'''
|
'''
|
||||||
words = string.split(' ')
|
words = string.split(' ')
|
||||||
if balance:
|
if balance:
|
||||||
|
@ -83,20 +83,20 @@ def wrapString(string, length=80, separator='\n', balance=False):
|
||||||
break
|
break
|
||||||
lines = ['']
|
lines = ['']
|
||||||
for word in words:
|
for word in words:
|
||||||
if len(lines[len(lines) - 1] + word + ' ') <= length + 1:
|
if len(lines[len(lines) - 1] + word + u' ') <= length + 1:
|
||||||
# word fits in current line
|
# word fits in current line
|
||||||
lines[len(lines) - 1] += word + ' ';
|
lines[len(lines) - 1] += word + u' ';
|
||||||
else:
|
else:
|
||||||
if len(word) <= length:
|
if len(word) <= length:
|
||||||
# word fits in next line
|
# word fits in next line
|
||||||
lines.append(word + ' ')
|
lines.append(word + u' ')
|
||||||
else:
|
else:
|
||||||
# word is longer than line
|
# word is longer than line
|
||||||
position = length - len(lines[len(lines) - 1])
|
position = length - len(lines[len(lines) - 1])
|
||||||
lines[len(lines) - 1] += word[0:position]
|
lines[len(lines) - 1] += word[0:position]
|
||||||
for i in range(position, len(word), length):
|
for i in range(position, len(word), length):
|
||||||
lines.append(word[i:i+length]);
|
lines.append(word[i:i+length]);
|
||||||
lines[len(lines) - 1] += ' '
|
lines[len(lines) - 1] += u' '
|
||||||
return separator.join(lines).strip()
|
return separator.join(lines).strip()
|
||||||
|
|
||||||
def truncateString(string, length, padding='...', position='right'):
|
def truncateString(string, length, padding='...', position='right'):
|
||||||
|
@ -178,37 +178,37 @@ def getValidFilename(s):
|
||||||
|
|
||||||
def getTextList(list_, last_word='or'):
|
def getTextList(list_, last_word='or'):
|
||||||
"""
|
"""
|
||||||
>>> getTextList(['a', 'b', 'c', 'd'])
|
>>> getTextList([u'a', u'b', u'c', u'd'])
|
||||||
'a, b, c or d'
|
u'a, b, c or d'
|
||||||
>>> getTextList(['a', 'b', 'c'], 'and')
|
>>> getTextList([u'a', u'b', u'c'], 'and')
|
||||||
'a, b and c'
|
u'a, b and c'
|
||||||
>>> getTextList(['a', 'b'], 'and')
|
>>> getTextList([u'a', u'b'], 'and')
|
||||||
'a and b'
|
u'a and b'
|
||||||
>>> getTextList(['a'])
|
>>> getTextList([u'a'])
|
||||||
'a'
|
u'a'
|
||||||
>>> getTextList([])
|
>>> getTextList([])
|
||||||
''
|
''
|
||||||
"""
|
"""
|
||||||
if len(list_) == 0: return ''
|
if len(list_) == 0: return ''
|
||||||
if len(list_) == 1: return list_[0]
|
if len(list_) == 1: return list_[0]
|
||||||
return '%s %s %s' % (', '.join([str(i) for i in list_][:-1]), last_word, list_[-1])
|
return u'%s %s %s' % (u', '.join([unicode(i) for i in list_][:-1]), last_word, list_[-1])
|
||||||
|
|
||||||
def getListText(text, last_word='or'):
|
def getListText(text, last_word='or'):
|
||||||
"""
|
"""
|
||||||
>>> getListText('a, b, c or d')
|
>>> getListText(u'a, b, c or d')
|
||||||
['a', 'b', 'c', 'd']
|
[u'a', u'b', u'c', u'd']
|
||||||
>>> getListText('a, b and c', 'and')
|
>>> getListText(u'a, b and c', u'and')
|
||||||
['a', 'b', 'c']
|
[u'a', u'b', u'c']
|
||||||
>>> getListText('a and b', 'and')
|
>>> getListText(u'a and b', u'and')
|
||||||
['a', 'b']
|
[u'a', u'b']
|
||||||
>>> getListText('a')
|
>>> getListText(u'a')
|
||||||
['a']
|
[u'a']
|
||||||
>>> getListText('')
|
>>> getListText(u'')
|
||||||
[]
|
[]
|
||||||
"""
|
"""
|
||||||
list_ = []
|
list_ = []
|
||||||
if text:
|
if text:
|
||||||
list_ = text.split(', ')
|
list_ = text.split(u', ')
|
||||||
if list_:
|
if list_:
|
||||||
i=len(list_)-1
|
i=len(list_)-1
|
||||||
last = list_[i].split(last_word)
|
last = list_[i].split(last_word)
|
||||||
|
|
Loading…
Reference in a new issue