Because return the not actually converted sentence may confuse someone that is careless about the supported locales.
And I think raise an error early can stop future big error for user codes.
|
def convert(s, locale, update=None): |
|
""" |
|
Main convert function. |
|
|
|
:param s: must be `unicode` (Python 2) or `str` (Python 3). |
|
:param locale: should be one of ``('zh-hans', 'zh-hant', 'zh-cn', 'zh-sg' |
|
'zh-tw', 'zh-hk', 'zh-my', 'zh-mo')``. |
|
:param update: a dict which updates the conversion table, eg. |
|
``{'from1': 'to1', 'from2': 'to2'}`` |
|
|
|
>>> print(convert('我幹什麼不干你事。', 'zh-cn')) |
|
我干什么不干你事。 |
|
>>> print(convert('我幹什麼不干你事。', 'zh-cn', {'不干': '不幹'})) |
|
我干什么不幹你事。 |
|
>>> print(convert('人体内存在很多微生物', 'zh-tw')) |
|
人體內存在很多微生物 |
|
""" |
|
if locale == 'zh' or locale not in Locales: |
|
# "no conversion" |
|
return s |
Let's see a mistake that may confuse the users in using the locale:
inputs = "我幹什麼不干你事"
print(convert(temp, locale='zh_cn'))
#output the same as the inputs but no warnings or erros
Maybe many users like me use zh_cn instead of the correct zh_cn by mistake sometime.
Because return the not actually converted sentence may confuse someone that is careless about the supported locales.
And I think raise an error early can stop future big error for user codes.
zhconv/zhconv/zhconv.py
Lines 235 to 254 in 078838e
Let's see a mistake that may confuse the users in using the locale:
Maybe many users like me use
zh_cninstead of the correctzh_cnby mistake sometime.