This commit is contained in:
7ae 2024-04-14 17:50:43 -07:00
parent d8cd9b3189
commit d0032a55ce
2 changed files with 175 additions and 87 deletions

View file

@ -1,34 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<head>
<title>Soli</title>
<link rel="stylesheet" href="./vendor/bootstrap.min.css">
<link rel="stylesheet" href="./vendor/bootstrap.min.css" />
<script src="./js/soli.js"></script>
</head>
</head>
<body>
<body>
<div class="container">
<h1>Soli</h1>
<p>
Soli is a tool to convert a text from Hangul to Latin alphabet.
</p>
<p>Soli is a tool to convert a text from Hangul to Latin alphabet.</p>
<form>
<div class="form-group mb-2">
<label for="input" class="fw-bold small">Hangul</label>
<textarea id="input" class="form-control" rows="2"
rows="2">모든 인간은 태어날 때부터 자유로우며 그 존엄과 권리에 있어 평등하다. 인간은 천부적으로 이성과 양심을 부여받았으며 서로 형제애의 정신으로 행동하여야 한다.</textarea>
<button type="button" class="btn btn-sm btn-success my-1" onclick="convert();">Submit Query</button>
<textarea id="input" class="form-control" rows="2" rows="2">
모든 인간은 태어날 때부터 자유로우며 그 존엄과 권리에 있어 평등하다. 인간은 천부적으로 이성과 양심을 부여받았으며 서로 형제애의 정신으로 행동하여야 한다.</textarea
>
<button
type="button"
class="btn btn-sm btn-success my-1"
onclick="convert();"
>
Submit Query
</button>
</div>
<div class="form-group">
<label for="output" class="fw-bold small">Romaja (romanization)</label>
<label for="output" class="fw-bold small"
>Lomaja (romanization)</label
>
<textarea id="out" class="form-control" rows="2" readonly></textarea>
<button type="button" class="btn btn-sm btn-success my-1" onclick="clipboard();">Copy to
Clipboard</button>
<button
type="button"
class="btn btn-sm btn-success my-1"
onclick="clipboard();"
>
Copy to Clipboard
</button>
</div>
</form>
</div>
<!-- @date 2022 -->
</body>
</body>
</html>

View file

@ -1,75 +1,150 @@
//@date 2022
const dict = {
"ㄱ": "g",
"ㄴ": "n",
"ㄷ": "d",
"ㄹ": "l",
"ㅁ": "m",
"ㅂ": "b",
"ㅅ": "s",
"ㅇ": "ng",
"ㅈ": "j",
"ㅊ": "ch",
"ㅋ": "k",
"ㅌ": "t",
"ㅍ": "p",
"ㅎ": "h",
"ㄲ": "k",
"ㄸ": "tt",
"ㅃ": "pp",
"ㅆ": "s",
"ㅉ": "jj",
"ㄳ": "gs",
"ㄵ": "nj",
"ㄶ": "nh",
"ㄺ": "lg",
"ㄻ": "lm",
"ㄼ": "lb",
"ㄽ": "ls",
"ㄾ": "lt",
"ㄿ": "lp",
"ㅀ": "lh",
"ㅄ": "bs",
"ㅏ": "a",
"ㅑ": "ya",
"ㅓ": "o",
"ㅕ": "yo",
"ㅗ": "o",
"ㅛ": "yo",
"ㅜ": "u",
"ㅠ": "yu",
"ㅡ": "u",
"ㅣ": "i",
"ㅐ": "e",
"ㅔ": "e",
"ㅒ": "ye",
"ㅖ": "ye",
"ㅘ": "wa",
"ㅙ": "oe",
"ㅚ": "oe",
"ㅞ": "oe",
"ㅝ": "wo",
"ㅟ": "wi",
"ㅢ": "ui"
: "g",
: "n",
: "d",
: "l",
: "m",
: "b",
: "s",
: "ng",
: "j",
: "ch",
: "k",
: "t",
: "p",
: "h",
: "k",
: "t",
: "p",
: "s",
: "j",
: "gs",
: "nj",
: "nh",
: "lg",
: "lm",
: "lb",
: "ls",
: "lt",
: "lp",
: "lh",
: "bs",
: "a",
: "ya",
: "o",
: "yo",
: "o",
: "yo",
: "u",
: "yu",
: "u",
: "i",
: "e",
: "e",
: "ye",
: "ye",
: "oa",
: "oe",
: "oe",
: "oe",
: "uo",
: "ui",
: "ui",
};
const hangul_f = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'];
const hangul_m = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ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g)) {
if (
input[i].match(
/[\uac00-\ud7af]|[\u1100-\u11ff]|[\u3130-\u318f]|[\ua960-\ua97f]|[\ud7b0-\ud7ff]/g
)
) {
const ga = 44032;
let unicode = input[i].charCodeAt(0);
unicode = unicode - ga;
let fi = parseInt(unicode / 588);
let mi = parseInt((unicode - (fi * 588)) / 28);
let mi = parseInt((unicode - fi * 588) / 28);
let ei = parseInt(unicode % 28);
if (hangul_f[fi] && hangul_f[fi] != "ㅇ") {
@ -91,7 +166,10 @@ function convert() {
for (var i = 0; i < out.length; i++) {
if (["s", "j", "ch", "h"].includes(out[i])) {
if (i + 1 < out.length && ["a", "e", "i", "o", "u", "y", "w"].includes(out[i + 1])) {
if (
i + 1 < out.length &&
["a", "e", "i", "o", "u", "y", "w"].includes(out[i + 1])
) {
continue;
} else {
out = out.substring(0, i) + "t" + out.substring(i + 1);