On-the-fly Conversion to Pinyin using Chrome Extension: ZH-CN (GB2312) <---> ZH-TW (BIG5)


Simplified/Traditional Chinese is a chrome Extension that allows you to convert from ZH-CN (GB2312) to ZH-TW(BIG5) and vice versa.

I developed this tool because I feel more confortable in reading Simplified Chinese and I believe some others prefer the Traditional Chinese.

Today, I have added a feature to convert Chinese characters (either in Simplified or Traditional Chinese) to Pinyin, which is used to pronounce the character characters.

convert-to-pinyin-chrome-extension On-the-fly Conversion to Pinyin using Chrome Extension: ZH-CN (GB2312) <---> ZH-TW (BIG5) chrome extension javascript

convert-to-pinyin-chrome-extension

How it works

For example, refresh the page, will convert the following:

traditional-chinese On-the-fly Conversion to Pinyin using Chrome Extension: ZH-CN (GB2312) <---> ZH-TW (BIG5) chrome extension javascript

traditional-chinese

to:

pinyin On-the-fly Conversion to Pinyin using Chrome Extension: ZH-CN (GB2312) <---> ZH-TW (BIG5) chrome extension javascript

pinyin

Technology Stack

Chrome Extension, Javascript.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let testChinese = (cc, i) =>{
    return (cc.charCodeAt(i) > 10000);
}
 
let Pinyin = (cc) => {
    let str = '';
    for (let i = 0; i < cc.length; ++ i) {
        if (testChinese(cc, i)) {
            if (cc[i] in pinyin_data) {
                let ts = pinyin_data[cc[i]];
                ts = ts.split(',')[0].slice(0, -1);
                str += ts[0].toUpperCase();
                str += ts.substring(1);
                str += " ";
            } else {
                str += cc[i];
            }
        } else {
            str += cc[i];
        }
    }
    return str.trim();
}
let testChinese = (cc, i) =>{
    return (cc.charCodeAt(i) > 10000);
}

let Pinyin = (cc) => {
    let str = '';
    for (let i = 0; i < cc.length; ++ i) {
        if (testChinese(cc, i)) {
            if (cc[i] in pinyin_data) {
                let ts = pinyin_data[cc[i]];
                ts = ts.split(',')[0].slice(0, -1);
                str += ts[0].toUpperCase();
                str += ts.substring(1);
                str += " ";
            } else {
                str += cc[i];
            }
        } else {
            str += cc[i];
        }
    }
    return str.trim();
}

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
348 words
Last Post: PHP Job Searching using Zip-Recruiter API
Next Post: The First Utopian Moderator Chrome Extension

The Permanent URL is: On-the-fly Conversion to Pinyin using Chrome Extension: ZH-CN (GB2312) <---> ZH-TW (BIG5)

Leave a Reply