5

Early in the history of japanese.SE one user created an enhancement that made it easy for editors to include phonetic spelling with Han characters. It was so popular that Stack Exchange took it and made it a standard feature of the site.

In Japanese you typically add Japanese phonetic script (hiragana and katakana) to characters (known as Kanji in Japanese). This is common not just in material for learners but also for Japanese readers where it will be added just for the the obscure characters that many Japanese might not know how to pronounce. This is known as either "furigana" or "ruby text".

The same thing is not so common in Chinese text, but it's still possible. And since many of us using chinese.SE are learners who find Pinyin less difficult (though still not always easy) than Hanzi, it would still be of benefit.

It does not automatically decide the pinyin for the characters, the editor has to specifically include it using some simple formatting.

The result is that the pinyin would be displayed abover the characters, so easy to ignore for people who can read hanzi well enough. At present we right the hanzi and pinyin next to each other, or in one recent post the editor "interleaved" the characters and pinyin one-by-one, which is not very easy to read.

What do others think?


I've started a topic on the Japanese JL&U so our interested users here can discuss the feature with the users there, and see how it works. Currently it does not "just work" for Pinyin, but we might found out if they can modify it easily to work.

6

I've hacked together a derivative of the JLU script that should work rudimentarily as a proof-of-concept. You can download it from this pastebin link and install it however you usually install userscripts in your browser. I haven't tested this besides in Chrome, so if it doesn't work in another recent browser, let me know.

Basically, I removed support for okurigana and pitch accent (since, as far as I know, Mandarin doesn't have those things) and added auto-conversion for things like zhong1wen2 to zhōngwén (as Don Kirkby requested). (I also made the regexes a bit more readable - more on that later.)

Structurally, this script behaves like the JLU helper script. You can write things like:

象形字{xiàngxíngzì}
指事字{zhi3shi4zi4}
会[意]{yì}字
假借{jia3jie4}字{zi4}

and if you have the script enabled, these things automagically convert to furigana-style annotations:

how the annotations should look

If you include the pinyin in "numeric" form (like the second and fourth examples above), it will also automatically be segmented so that each syllable is placed above its corresponding character.

Since my knowledge of Chinese orthography is extremely minimal, I need to know some more things in order to improve this:

  1. Can pinyin written in "diacritic" form (like the first and third examples above) be unambiguously broken into syllables (by itself, without reference to the characters)? If so, I can figure out how to implement automatic segmentation for diacritic-form pinyin.
  2. Does this site cover Chinese languages besides Mandarin, and if so, would there be any demand for tonal annotations for other languages? I don't know anything at all about languages besides Mandarin, so I'd need pointers to some basic resources on orthography.
  3. On JLU, there's also support for annotations of the form 神【かみ】 (in addition to square brackets []) because that's how dictionaries do it. Does Chinese have any similar practices that ought to be supported?
  4. On JLU, the following characters behave like punctuation for the purposes of the helper script: .、。--/。<>()\(\)≪≫;;::!!==≡≠≒$¥?\?&##@@“‘”’. Are there any additional punctuation characters for Chinese?
  5. Are there any characters that would require annotation outside the UTF-8 range from U+4E00 to U+FEED? That's what JLU uses, and it seems to cover all common CJK characters, but the CJK Unified Ideographs Extension ranges fall outside that, and I don't know if you folks would need that. (If you're not familiar with Unicode ranges, take a look at this site.)

If this turns out to be useful to you folks, hopefully some friendly SE employee will come by and implement this properly at some point in the future.

  • 1
    Beat me to it :) Ah well, I've uploaded my version to gist.github.com/cyphr/7562487 in case any of it's useful. – cypher Nov 20 '13 at 13:03
  • Besides not being sure what you mean by "outside the UTF-8 range" this looks great, thanks! (Maybe you just mean that particular Unicode range since UTF-8 is capable of the full Unicode repertoire.) – hippietrail Nov 20 '13 at 14:52
  • @hippietrail Yes, I mean the part of UTF-8 from U+4E00 to U+FEED. There are apparently some other CJK ideographs that live between U+20000 and U+2FA1F, but I don't know if any of those are of practical use on CLU. – senshin Nov 20 '13 at 14:56
  • There is a great regex library for JavaScript called XRegExp that can match han characters perfectly. You don't even have to include the library - you can just use it to generate the regexp and plug that in. – hippietrail Nov 20 '13 at 15:28
  • 1
    @hippietrail Oh, cool. I'll take a look at that. – senshin Nov 20 '13 at 15:31
  • 1
    A few things: there's an ie-specific font-family:"MS Gothic","MS ゴシック" CSS line to make sure Kana displays correctly, but I think it should be removed for Chinese. Also, it might be worth adding support for the fifth tone, so that e.g. 对不起{dui4bu5qi3} would be split one for each character. That's about all I can think of right now, you've done a very good job! – cypher Nov 20 '13 at 20:54
  • The pastebin link seems to be blocked by the Great Firewall. Is there another way to try this script in China? – hippietrail Nov 23 '13 at 17:42
  • @hippietrail Ooh, that's not good. Do either Github or Bitbucket make it through the firewall? Or if not, do you have any other suggestions for text hosting sites? (I'll post a fixed-up version using your and cypher's suggestions in a day or two.) – senshin Nov 24 '13 at 7:32
  • @senshin: The main page of both Github and Bitbucket loaded fine for me here in 呼和浩特. – hippietrail Nov 24 '13 at 10:06
2

I think it would be a nice option when you particularly want to discuss the pronunciation of a character, but I wouldn't use it regularly.

To help people visualize what it would look like, I posted an example of pinyin in ruby text at GitHub. If the feature supported converting zhong1wen2 to zhōngwén that would make it easier to use.

  • I like this idea more. It's more friendly to less tech-savvy individuals. – deutschZuid Dec 4 '13 at 3:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .