先上代码
<!DOCTYPE html>
<html lang="en">
<head>
<title>阿卡林语简化拼音转标准拼音</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="bigBox">
<h1>阿卡林语简化拼音转标准拼音</h1>
<p id="shijian">2020年01月01日 12:00:00</p>
<p id="pinyinShili">简化拼音示例:pin1 yin1 | 标准拼音示例:pīn yīn</p>
<textarea id='input_div' placeholder=" 输入需要转换的简化拼音,多个拼音请使用空格进行分隔"></textarea>
<p></p>
<!-- <hr> -->
<button id="btn1">阿卡林语简化拼音转换成标准拼音</button>
<button id="btn2">普通话简化拼音转换成标准拼音</button>
<button id="btn3">清空</button>
<p></p>
<!-- <hr> -->
<textarea id='outDiv' placeholder=" 转化结果在这里"></textarea>
友商链接:
<a href="http://xh.5156edu.com/conversion.html" target="_blank">汉字转普通话拼音、</a>
<a href="https://hongkongvision.com/tool/cc_py_conv_zh" target="_blank">汉字转广州话拼音</a>
</div>
<style>
#shijian {
position: absolute;
left: 392px;
top: 35px;
font-size: 16px;
font-weight: 400;
}
h1 {
margin-top: -10px;
font-size: 26px;
}
#pinyinShili {
margin-top: -10px;
font-size: 12px;
}
a {
color: #000000;
cursor: pointer;
text-decoration: none;
font-weight: 400;
}
a:hover {
/* color: blueviolet; */
color: #000;
font-weight: 600;
}
#bigBox {
margin: 10px auto;
width: 680px;
height: 710px;
border: 1px solid #ddd;
box-shadow: 5px 5px 3px #888888;
position: relative;
}
div {
box-sizing: border-box;
margin: 10px;
padding: 20px;
}
#btn1,
#btn2 {
width: 260px;
height: 40px;
font-size: 15px;
margin-left: 10px;
font-weight: 400;
cursor: pointer;
}
#btn3 {
width: 70px;
height: 40px;
font-size: 15px;
margin-left: 10px;
font-weight: 400;
cursor: pointer;
}
#btn1:hover,
#btn2:hover,
#btn3:hover {
font-weight: 600;
}
#input_div,
#outDiv {
resize: none;
width: 640px;
height: 260px;
text-rendering: auto;
color: -internal-light-dark(black, white);
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
display: inline-block;
text-align: start;
appearance: textarea;
background-color: -internal-light-dark(rgb(255, 255, 255), rgb(59, 59, 59));
-webkit-rtl-ordering: logical;
flex-direction: column;
cursor: text;
white-space: pre-wrap;
overflow-wrap: break-word;
box-sizing: border-box;
margin: 0em;
font: 400 13.3333px Arial;
font-size: 18px;
border-width: 1px;
border-style: solid;
border-color: -internal-light-dark(rgb(118, 118, 118), rgb(133, 133, 133));
border-image: initial;
padding: 2px 0px 0px 2px;
}
</style>
</body>
<!-- 阿卡林语简化拼音转换成标准拼音 -->
<script>
function getRealAkalinPinyin(str = 'qing3 shu1 ru4 pin1 yin1') {
str = str.toLowerCase()
str = str.replace(/[\r\n]/g, ' ')
str = str.replace(/v/g, 'ü')
var strArr = str.split(' ')
var result = []
for (let index = 0; index < strArr.length; index++) {
result.push(transToStdAkalinPinyin(strArr[index]))
}
for (let tag = 0; tag < strArr.length; tag++) {
result[tag] = processingAkalinPinyinError(result[tag].toString())
}
var printResult = result.join('').toString()
for (let jj = 0; jj < printResult.length; jj++) {
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
}
console.log(printResult);
return printResult;
}
function transToStdAkalinPinyin(pinyin) {
let temp = pinyin.split('')
if (temp[temp.length - 1] != '1' && temp[temp.length - 1] != '2' &&
temp[temp.length - 1] != '3' && temp[temp.length - 1] != '4') {
temp.push(' ')
return temp.join('')
} else {
if (temp[temp.length - 1] == "1") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'ā' }
if (temp[index] == 'o') { temp[index] = 'ō' }
if (temp[index] == 'e') { temp[index] = 'ē' }
if (temp[index] == 'i') { temp[index] = 'ī' }
if (temp[index] == 'u') { temp[index] = 'ū' }
if (temp[index] == 'ü') { temp[index] = 'ǖ' }
}
}
if (temp[temp.length - 1] == "2") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'á' }
if (temp[index] == 'o') { temp[index] = 'ó' }
if (temp[index] == 'e') { temp[index] = 'é' }
if (temp[index] == 'i') { temp[index] = 'í' }
if (temp[index] == 'u') { temp[index] = 'ú' }
if (temp[index] == 'ü') { temp[index] = 'ǘ' }
}
}
if (temp[temp.length - 1] == "3") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'ǎ' }
if (temp[index] == 'o') { temp[index] = 'ǒ' }
if (temp[index] == 'e') { temp[index] = 'ě' }
if (temp[index] == 'i') { temp[index] = 'ǐ' }
if (temp[index] == 'u') { temp[index] = 'ǔ' }
if (temp[index] == 'ü') { temp[index] = 'ǚ' }
}
}
if (temp[temp.length - 1] == "4") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'à' }
if (temp[index] == 'o') { temp[index] = 'ò' }
if (temp[index] == 'e') { temp[index] = 'è' }
if (temp[index] == 'i') { temp[index] = 'ì' }
if (temp[index] == 'u') { temp[index] = 'ù' }
if (temp[index] == 'ü') { temp[index] = 'ǜ' }
}
}
temp[temp.length - 1] = ''
temp.push(' ')
return temp.join('')
}
}
function processingAkalinPinyinError(str) {
var n = str
n = n.replace("āī", "āi").replace("áí", "ái").replace("ǎǐ", "ǎi").replace("àì", "ài");
n = n.replace("īō", "iō").replace("íó", "ió").replace("ǐǒ", "iǒ").replace("ìò", "iò");
n = n.replace("ūō", "uō").replace("úó", "uó").replace("ǔǒ", "uǒ").replace("ùò", "uò");
n = n.replace("ūū", "ūu").replace("úú", "úu").replace("ǔǔ", "ǔu").replace("ùù", "ùu");
n = n.replace("ǖē", "üē").replace("ǘé", "üé").replace("ǚě", "üě").replace("ǜè", "üè");
n = n.replace("ūā", "uā").replace("úá", "uá").replace("ǔǎ", "uǎ").replace("ùà", "uà");
n = n.replace("ūē", "uē").replace("úé", "ué").replace("ǔě", "uě").replace("ùè", "uè");
n = n.replace("īē", "iē").replace("íé", "ié").replace("ǐě", "iě").replace("ìè", "iè");
n = n.replace("āō", "āo").replace("áó", "áo").replace("ǎǒ", "ǎo").replace("àò", "ào");
n = n.replace("ēī", "ēi").replace("éí", "éi").replace("ěǐ", "ěi").replace("èì", "èi");
n = n.replace("īā", "iā").replace("íá", "iá").replace("ǐǎ", "iǎ").replace("ìà", "ià");
n = n.replace("īū", "iū").replace("íú", "iú").replace("ǐǔ", "iǔ").replace("ìù", "iù");
n = n.replace("ōū", "ōu").replace("óú", "óu").replace("ǒǔ", "ǒu").replace("òù", "òu");
n = n.replace("ūī", "uī").replace("úí", "uí").replace("ǔǐ", "uǐ").replace("ùì", "uì");
n = n.replace("ǖāi", "üāi").replace("ǘái", "üái").replace("ǚǎi", "üǎi").replace("ǜài", "üài");
n = n.replace("ǖōn", "üōn").replace("ǘón", "üón").replace("ǚǒn", "üǒn").replace("ǜòn", "üòn");
n = n.replace("ǖān", "üān").replace("ǘán", "üán").replace("ǚǎn", "üǎn").replace("ǜàn", "üàn");
n = n.replace("īāo", "iāo").replace("íáo", "iáo").replace("ǐǎo", "iǎo").replace("ìào", "iào");
n = n.replace("īān", "iān").replace("íán", "ián").replace("ǐǎn", "iǎn").replace("ìàn", "iàn");
n = n.replace("ūān", "uān").replace("úán", "uán").replace("ǔǎn", "uǎn").replace("ùàn", "uàn");
n = n.replace("ūēr", "uēr").replace("úér", "uér").replace("ǔěr", "uěr").replace("ùèr", "uèr");
n = n.replace("īēng", "iēng").replace("íéng", "iéng").replace("ǐěng", "iěng").replace("ìèng", "ièng");
n = n.replace("īōng", "iōng").replace("íóng", "ióng").replace("ǐǒng", "iǒng").replace("ìòng", "iòng");
return n
}
//---------------
document.getElementById('btn1').onclick = function () {
var text = document.getElementById('input_div').value
// console.log(text)
var text2 = getRealAkalinPinyin(text)
// console.log(text2)
document.getElementById('outDiv').value = text2
}
</script>
<!-- 普通话简化拼音转换成标准拼音 -->
<script>
function getStdPutonghuaPinyin(str = 'qing3 shu1 ru4 pin1 yin1') {
str = str.toLowerCase()
str = str.replace(/[\r\n]/g, ' ')
str = str.replace(/v/g, 'ü')
var strArr = str.split(' ')
var result = []
for (let index = 0; index < strArr.length; index++) {
result.push(transToStd(strArr[index]))
}
for (let tag = 0; tag < strArr.length; tag++) {
result[tag] = errorRecovery(result[tag].toString())
}
var printResult = result.join('').toString()
for (let jj = 0; jj < printResult.length; jj++) {
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
printResult = printResult.replace(" ", " ");
}
console.log(printResult);
return printResult;
}
function transToStd(pinyin) {
let temp = pinyin.split('')
if (temp[temp.length - 1] != '1' && temp[temp.length - 1] != '2' &&
temp[temp.length - 1] != '3' && temp[temp.length - 1] != '4') {
temp.push(' ')
return temp.join('')
} else {
if (temp[temp.length - 1] == "1") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'ā' }
if (temp[index] == 'o') { temp[index] = 'ō' }
if (temp[index] == 'e') { temp[index] = 'ē' }
if (temp[index] == 'i') { temp[index] = 'ī' }
if (temp[index] == 'u') { temp[index] = 'ū' }
if (temp[index] == 'ü') { temp[index] = 'ǖ' }
}
}
if (temp[temp.length - 1] == "2") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'á' }
if (temp[index] == 'o') { temp[index] = 'ó' }
if (temp[index] == 'e') { temp[index] = 'é' }
if (temp[index] == 'i') { temp[index] = 'í' }
if (temp[index] == 'u') { temp[index] = 'ú' }
if (temp[index] == 'ü') { temp[index] = 'ǘ' }
}
}
if (temp[temp.length - 1] == "3") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'ǎ' }
if (temp[index] == 'o') { temp[index] = 'ǒ' }
if (temp[index] == 'e') { temp[index] = 'ě' }
if (temp[index] == 'i') { temp[index] = 'ǐ' }
if (temp[index] == 'u') { temp[index] = 'ǔ' }
if (temp[index] == 'ü') { temp[index] = 'ǚ' }
}
}
if (temp[temp.length - 1] == "4") {
for (let index = 0; index < temp.length; index++) {
if (temp[index] == 'a') { temp[index] = 'à' }
if (temp[index] == 'o') { temp[index] = 'ò' }
if (temp[index] == 'e') { temp[index] = 'è' }
if (temp[index] == 'i') { temp[index] = 'ì' }
if (temp[index] == 'u') { temp[index] = 'ù' }
if (temp[index] == 'ü') { temp[index] = 'ǜ' }
}
}
temp[temp.length - 1] = ''
temp.push(' ')
return temp.join('')
}
}
function errorRecovery(str) {
var n = str
n = n.replace("āī", "āi").replace("áí", "ái").replace("ǎǐ", "ǎi").replace("àì", "ài");
n = n.replace("ēī", "ēi").replace("éí", "éi").replace("ěǐ", "ěi").replace("èì", "èi");
n = n.replace("ūī", "uī").replace("úí", "uí").replace("ǔǐ", "uǐ").replace("ùì", "uì");
n = n.replace("āō", "āo").replace("áó", "áo").replace("ǎǒ", "ǎo").replace("àò", "ào");
n = n.replace("ōū", "ōu").replace("óú", "óu").replace("ǒǔ", "ǒu").replace("òù", "òu");
n = n.replace("īū", "iū").replace("íú", "iú").replace("ǐǔ", "iǔ").replace("ìù", "iù");
n = n.replace("īē", "iē").replace("íé", "ié").replace("ǐě", "iě").replace("ìè", "iè");
n = n.replace("ǖē", "üē").replace("ǘé", "üé").replace("ǚě", "üě").replace("ǜè", "üè");
n = n.replace("ūā", "uā").replace("úá", "uá").replace("ǔǎ", "uǎ").replace("ùà", "uà");
n = n.replace("īā", "iā").replace("íá", "iá").replace("ǐǎ", "iǎ").replace("ìà", "ià");
n = n.replace("īān", "iān").replace("íán", "ián").replace("ǐǎn", "iǎn").replace("ìàn", "iàn");
n = n.replace("ūān", "uān").replace("úán", "uán").replace("ǔǎn", "uǎn").replace("ùàn", "uàn");
n = n.replace("īōn", "iōn").replace("íón", "ión").replace("ǐǒn", "iǒn").replace("ìòn", "iòn");
n = n.replace("īāo", "iāo").replace("íáo", "iáo").replace("ǐǎo", "iǎo").replace("ìào", "iào");
n = n.replace("īōng", "iōng").replace("íóng", "ióng").replace("ǐǒng", "iǒng").replace("ìòng", "iòng");
return n
}
// getStdPutonghuaPinyin('')
document.getElementById('btn2').onclick = function () {
var text3 = document.getElementById('input_div').value
// console.log(text3)
var text4 = getRealAkalinPinyin(text3)
// console.log(text4)
text4 = text4.replace(/jǖ/g, "jū").replace(/jǘ/g, "jú").replace(/jǚ/g, "jǔ").replace(/jǜ/g, "jù");
text4 = text4.replace(/qǖ/g, "qū").replace(/qǘ/g, "qú").replace(/qǚ/g, "qǔ").replace(/qǜ/g, "qù");
text4 = text4.replace(/xǖ/g, "xū").replace(/xǘ/g, "xú").replace(/xǚ/g, "xǔ").replace(/xǜ/g, "xù");
text4 = text4.replace(/yǖ/g, "yū").replace(/yǘ/g, "yú").replace(/yǚ/g, "yǔ").replace(/yǜ/g, "yù");
document.getElementById('outDiv').value = text4
}
</script>
<!-- 清空输入输出框 -->
<script>
document.getElementById('btn3').onclick = function () {
document.getElementById('input_div').value = '';
document.getElementById('outDiv').value = '';
}
</script>
<!-- 显示时间 -->
<script>
function reTime() {
var shijianP = document.getElementById('shijian');
var time = new Date();
var nian = time.getFullYear();
var yue = time.getMonth() + 1;
if (yue < 10) {
yue = '0' + yue;
}
var ri = time.getDate();
if (ri < 10) {
ri = '0' + ri;
}
var shi = time.getHours();
if (shi < 10) {
shi = '0' + shi;
}
var fen = time.getMinutes();
if (fen < 10) {
fen = '0' + fen;
}
var miao = time.getSeconds();
if (miao < 10) {
miao = '0' + miao;
}
var milliSeconds = time.getMilliseconds()
var haomiao = 0;
if (milliSeconds < 100) {
haomiao = '0' + milliSeconds;
} else {
haomiao = milliSeconds + '0';
}
haomiao = haomiao.substr(0, 2);
var libaiji = time.getDay();
if (libaiji == 0) {
libaiji = "天"
} else if (libaiji == 1) {
libaiji = "一"
} else if (libaiji == 2) {
libaiji = "二"
} else if (libaiji == 3) {
libaiji = "三"
} else if (libaiji == 4) {
libaiji = "四"
} else if (libaiji == 5) {
libaiji = "五"
} else if (libaiji == 6) {
libaiji = "六"
}
var timeText = nian + '年' + yue + '月' + ri + '日' + ' ' + '星期' + libaiji + ' ' + shi + ':' + fen + ':' + miao + ':' + haomiao;
shijianP.innerText = timeText;
}
function reTimeInterval() {
setTimeout(() => {
reTime();
reTimeInterval();
}, 1000 / 30);
}
reTimeInterval();
</script>
</html>
运行效果
试用
原话:阿卡林语简化拼音转标准拼音
输入:a1 ka3 lin2 yv3 jian3 hua4 pin1 yin1 zhuan3 huan4 qi4
输出:ā kǎ lín yǔ jiǎn huà pīn yīn zhuǎn huàn qì