Created
August 8, 2014 13:47
-
-
Save katylava/c3fbe1c5b466c72a011e to your computer and use it in GitHub Desktop.
Simple Korean romanization from http://www.tckerrigan.com/Misc/Korean+romanizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var choseongInit = 'G;GG;N;D;DD;L;M;B;BB;S;SS;;J;JJ;C;K;T;P;H'; | |
var jungseongInit = 'A;AE;YA;YAE;EO;E;YEO;YE;O;WA;WAE;OE;YO;U;WEO;WE;WI;YU;EU;YI;I'; | |
var jongseongInit = ';G;GG;GS;N;NJ;NH;D;L;LG;LM;LB;LS;LT;LP;LH;M;B;BS;S;SS;NG;J;C;K;T;P;H'; | |
function Romanize() | |
{ | |
choseongList = choseongInit.split(';'); | |
jungseongList = jungseongInit.split(';'); | |
jongseongList = jongseongInit.split(';'); | |
strKorean = document.getElementById('idKorean').value; | |
outStr = ''; | |
for (i = 0; i < strKorean.length; i++) | |
{ | |
charCode = strKorean.charCodeAt(i); | |
if (charCode < 44032 || charCode > 44032 + 11172) | |
{ | |
outStr += String.fromCharCode(charCode); | |
continue; | |
} | |
n = 44032; | |
for (choseong = 0;; choseong++) | |
{ | |
n += jungseongList.length * jongseongList.length; | |
if (n > charCode) | |
break; | |
} | |
n -= jungseongList.length * jongseongList.length; | |
for (jungseong = 0;; jungseong++) | |
{ | |
n += jongseongList.length; | |
if (n > charCode) | |
break; | |
} | |
n -= jongseongList.length; | |
jongseong = charCode - n; | |
outStr += choseongList[choseong] + jungseongList[jungseong] + jongseongList[jongseong]; | |
} | |
document.getElementById('idRoman').innerHTML = outStr.toLowerCase(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment