Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe raise a keyerror is a better way to process the locale not supported #8

Open
Raibows opened this issue Apr 22, 2021 · 0 comments

Comments

@Raibows
Copy link

Raibows commented Apr 22, 2021

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant