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

Tone Marks #14

Open
chid opened this issue Jun 2, 2014 · 5 comments
Open

Tone Marks #14

chid opened this issue Jun 2, 2014 · 5 comments

Comments

@chid
Copy link

chid commented Jun 2, 2014

Is it possible to also add in the tone marks?

eg.

Pinyin.t('中国', tonemarks: true) => "zhōng guó"

@flyerhzm
Copy link
Owner

flyerhzm commented Jun 2, 2014

@chid We already supported tone, see README, but it output like "zhong1 guo2" rather than "zhōng guó",

@chid
Copy link
Author

chid commented Jun 2, 2014

I realise that, I was wondering whether it is possible to add the symbols rather than the number.

@Pisces000221
Copy link

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.

@cuihq
Copy link
Contributor

cuihq commented Mar 6, 2015

👍

@Pisces000221
Copy link

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 %w(a o e i u v).each) 😜

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

4 participants