-
Notifications
You must be signed in to change notification settings - Fork 59
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
Tone Marks #14
Comments
@chid We already supported tone, see README, but it output like "zhong1 guo2" rather than "zhōng guó", |
I realise that, I was wondering whether it is possible to add the symbols rather than the number. |
I think we can approach this by adding an array like tones = [
['a', 'ā', 'á', 'ǎ', 'à'],
['e', ...],
...
] and if we want to get a special tone for a letter, we use: r = 'zhong' # 中
tone = 1
idx = 0
# If we have 'a', we put the sign above it
# Otherwise, we check 'o', 'e', 'i', 'u', 'yu'.
# If we have both 'i' and 'u', we put the sign above the one coming after the other
if r.index('a') then idx = r.index('a')
elsif r.index('o') then idx = r.index('o')
elsif r.index('e') then idx = r.index('e')
elsif r.index('i') and r.index('u') then
if r.index('i') > r.index('u') then idx = r.index('i')
else idx = r.index('u') end
elsif r.index('i') then idx = r.index('i')
elsif r.index('u') then idx = r.index('u')
elsif r.index('ǖ') then idx = r.index('ǖ')
end
for i in 0..tones.count-1
if tones[i][0] == r[idx] then
r[idx] = tones[i][tone]
break
end
end Maybe this could work. |
👍 |
I was writing some Lua code at that time and the code above looks like Lua... Thanks for improving it and making it Ruby-style (like |
Is it possible to also add in the tone marks?
eg.
Pinyin.t('中国', tonemarks: true) => "zhōng guó"
The text was updated successfully, but these errors were encountered: