Jump to content
Chinese-Forums
  • Sign Up

Pinyin tone marker


dhl

Recommended Posts

Does anyone here know of any program that instanstly marks the tone over av word. Now i use a macro i Office and i think its a bit of a hassle...

for instance if you write "ni3" and instanstly when the 3-button i pressed the output changes to "nĭ". It seems like a fairly simple program to produce, if you know how to :shock: but i haven´t found any here on this forum or anywhere else that i looked either.

P.S. I don´t want to hear of any NJstar :wink:

Link to comment
Share on other sites

Haha, yep a pretty simple program to write, I could write it for you pretty quickly... how much would you willing to pay for it though? :-)

But why not just use something like http://pinyin.info/unicode/marks3.html.. unless for some reason you absolutely have to have the tone marks appear instantly..

Link to comment
Share on other sites

this is php code to translate a single sound+tone into proper pinyin.

eg. hao3 -> hǎo

/**

* Take the pinyin sound and it's tone, and generate the proper piyin

*

* $sound String the raw pinyin sound

* $tone int The mandarin tone. From 1 to 5.

* returns String the full pinyin representation

*/

function doPinyin($sound, $tone) {

$pinyin = ""; //to feed the pinyin chars in

$toneinputted = false; //only change 1 vowel to pinyin!

//Find the first vowel in $sound

for ($counter = 0; $counter < strlen($sound); $counter++) {

if (!$toneinputted && $sound{$counter} === "a") {

if ($tone == "1") { $pinyin .= "ā"; }

if ($tone == "2") { $pinyin .= "á"; }

if ($tone == "3") { $pinyin .= "ǎ"; }

if ($tone == "4") { $pinyin .= "à"; }

if ($tone == "5") { $pinyin .= "a"; }

$toneinputted = true;

} else if (!$toneinputted && $sound{$counter} === "e") {

if ($tone == "1") { $pinyin .= "ē"; }

if ($tone == "2") { $pinyin .= "é"; }

if ($tone == "3") { $pinyin .= "ě"; }

if ($tone == "4") { $pinyin .= "è"; }

if ($tone == "5") { $pinyin .= "e"; }

$toneinputted = true;

} else if (!$toneinputted && $sound{$counter} === "i") {

if ($tone == "1") { $pinyin .= "ī"; }

if ($tone == "2") { $pinyin .= "í"; }

if ($tone == "3") { $pinyin .= "ǐ"; }

if ($tone == "4") { $pinyin .= "ì"; }

if ($tone == "5") { $pinyin .= "i"; }

$toneinputted = true;

} else if (!$toneinputted && $sound{$counter} === "o") {

if ($tone == "1") { $pinyin .= "ō"; }

if ($tone == "2") { $pinyin .= "ó"; }

if ($tone == "3") { $pinyin .= "ǒ"; }

if ($tone == "4") { $pinyin .= "ò"; }

if ($tone == "5") { $pinyin .= "o"; }

$toneinputted = true;

} else if (!$toneinputted && $sound{$counter} === "u") {

if ($tone == "1") { $pinyin .= "ū"; }

if ($tone == "2") { $pinyin .= "ú"; }

if ($tone == "3") { $pinyin .= "ǔ"; }

if ($tone == "4") { $pinyin .= "ù"; }

if ($tone == "5") { $pinyin .= "u"; }

$toneinputted = true;

} else {

$pinyin .= $sound{$counter}; //No vowel found, just copy character

}

}

return $pinyin;

}

Link to comment
Share on other sites

Join the conversation

You can post now and select your username and password later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Click here to reply. Select text to quote.

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...