Add Pokhwalish language
authorLanius Trolling <lanius@laniustrolling.dev>
Sun, 3 Sep 2023 12:15:47 +0000 (08:15 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sun, 3 Sep 2023 12:15:47 +0000 (08:15 -0400)
src/main/kotlin/info/mechyrdia/Factbooks.kt
src/main/kotlin/info/mechyrdia/lore/languages.kt [new file with mode: 0644]
src/main/kotlin/info/mechyrdia/lore/parser_tags.kt
src/main/kotlin/info/mechyrdia/lore/tylan_language.kt [deleted file]
src/main/resources/static/font/pokhval-alphabet.woff [new file with mode: 0644]
src/main/resources/static/init.js
src/main/resources/static/style.css

index 867d0df26dd3a74de4e208b520c89b3a99ef7d4d..6d430606f5f66d1890f19b97ba833dc146e3dc12 100644 (file)
@@ -223,6 +223,10 @@ fun Application.factbooks() {
                        call.respondText(TylanAlphabet.tylanToFontAlphabet(call.receiveText()))
                }
                
+               post("/pokhwal-lang") {
+                       call.respondText(PokhwalishAlphabet.pokhwalToFontAlphabet(call.receiveText()))
+               }
+               
                post("/preview-comment") {
                        call.respondText(
                                text = TextParserState.parseText(call.receiveText(), TextParserCommentTags.asTags, Unit),
diff --git a/src/main/kotlin/info/mechyrdia/lore/languages.kt b/src/main/kotlin/info/mechyrdia/lore/languages.kt
new file mode 100644 (file)
index 0000000..1e4d6a4
--- /dev/null
@@ -0,0 +1,127 @@
+package info.mechyrdia.lore
+
+object TylanAlphabet {
+       private val allowedTranslitCharacters = setOf(
+               ' ', '\r', '\n', '\t',
+               'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y',
+               '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+               '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+',
+               '[', '{', '}', ']', '\\', '|', '/', '<',
+               '.', ',', ':', ';', '\'', '"', '?', '>',
+       )
+       
+       private val replacements = listOf(
+               Regex("([0-9xy]+)(?![\\s0-9xy])") to "$1 ",
+               Regex("(?<![\\s0-9xy])([0-9xy]+)") to " $1",
+               
+               Regex("([a-pr-v'])m(?![\\w'])") to "$1A",
+               Regex("([a-pr-v'])n(?![\\w'])") to "$1E",
+               Regex("([a-ps-v'])r(?![\\w'])") to "$1H",
+               Regex("([ac-fh-jl-or-v'])s(?![\\w'])") to "$1I",
+               Regex("([a-pr-v'])t(?![\\w'])") to "$1Q",
+               
+               Regex("x") to "M",
+               Regex("y") to "N",
+               Regex("[qw-z]") to "",
+               
+               Regex("ch") to "C",
+               Regex("dh") to "D",
+               Regex("sh") to "S",
+               Regex("th") to "T",
+               
+               Regex("bs") to "B",
+               Regex("gs") to "G",
+               Regex("ks") to "K",
+               Regex("ps") to "P",
+               
+               Regex("b'([Is])") to "b$1",
+               Regex("g'([Is])") to "g$1",
+               Regex("k'([Is])") to "k$1",
+               Regex("p'([Is])") to "p$1",
+               
+               Regex("ff") to "F",
+               Regex("fv") to "V",
+               Regex("hj") to "J",
+               Regex("lh") to "L",
+               Regex("ll") to "L",
+               Regex("hl") to "L",
+               Regex("rh") to "R",
+               Regex("rr") to "R",
+               Regex("hr") to "R",
+               Regex("d'h") to "dh",
+               Regex("l'h") to "lh",
+               Regex("l'J") to "lJ",
+               Regex("r'h") to "rh",
+               Regex("r'J") to "rJ",
+               Regex("s'h") to "sh",
+               Regex("t'h") to "th",
+               Regex("h'l") to "hl",
+               Regex("h'r") to "hr",
+               Regex("B'h") to "Bh",
+               Regex("G'h") to "Gh",
+               Regex("K'h") to "Kh",
+               Regex("P'h") to "Ph",
+               Regex("c(?!h)") to "",
+               
+               Regex("ae") to "W",
+               Regex("au") to "X",
+               Regex("ea") to "Y",
+               Regex("ei") to "Z",
+               Regex("eo") to "w",
+               Regex("eu") to "x",
+               Regex("oa") to "y",
+               Regex("ou") to "z",
+               Regex("oe") to "O",
+               Regex("ui") to "U",
+               
+               Regex("i([aeiouOUw-zW-Z])") to "ij$1",
+               Regex("^([aeiouOUw-zW-Z])") to "'$1",
+               Regex("([^'BCDFGJKLPR-TVbdf-hj-npr-tv])([aeiouOUw-zW-Z])") to "$1'$2",
+               Regex("([aeiouOUw-zW-Z])([aeiouOUw-zW-Z])") to "$1'$2",
+       )
+       
+       fun tylanToFontAlphabet(tylan: String) = replacements.fold(tylan.lowercase().filter { it in allowedTranslitCharacters }) { partial, (regex, replacement) ->
+               partial.replace(regex, replacement)
+       }
+}
+
+object PokhwalishAlphabet {
+       private val allowedTranslitCharacters = setOf(
+               ' ', '\r', '\n', '\t',
+               'a', 'b', 'c', 'd', 'e', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'y', 'z',
+               '.', ',', '\'', '?', '!',
+       )
+       
+       private val replacements = listOf(
+               // Vowels
+               Regex("aa") to "A",
+               Regex("ae") to "A",
+               Regex("ee") to "E",
+               Regex("ei") to "E",
+               Regex("ey") to "E",
+               Regex("ie") to "I",
+               Regex("ii") to "I",
+               Regex("iy") to "I",
+               Regex("ao") to "O",
+               Regex("au") to "O",
+               Regex("oo") to "O",
+               Regex("ou") to "U",
+               Regex("uu") to "U",
+               // Consonants
+               Regex("tz") to "C",
+               Regex("hh") to "K",
+               Regex("kh") to "K",
+               Regex("gh") to "G",
+               Regex("ng(?![aeiouAEIOU])") to "N",
+               Regex("n'g") to "ng",
+               Regex("qh") to "Q",
+               Regex("th") to "T",
+               
+               Regex("ck") to "q",
+               Regex("k") to "q",
+       )
+       
+       fun pokhwalToFontAlphabet(pokhwal: String) = replacements.fold(pokhwal.lowercase().filter { it in allowedTranslitCharacters }) { partial, (regex, replacement) ->
+               partial.replace(regex, replacement)
+       }
+}
index 7c37e5d1358af38728bdd29741e647d26b4a7bde..f56ccdfadfb2b98bffc9656bcb5ba696a7a362a1 100644 (file)
@@ -294,7 +294,12 @@ enum class TextParserFormattingTag(val type: TextParserTagType<Unit>) {
                                "<span class=\"lang-tylan\">$recensored</span>"
                        } else if (tagParam?.equals("thedish", ignoreCase = true) == true)
                                "<span class=\"lang-thedish\">$content</span>"
-                       else if (tagParam?.equals("gothic", ignoreCase = true) == true)
+                       else if (tagParam?.equals("pokhval", ignoreCase = true) == true || tagParam?.equals("pokhwal", ignoreCase = true) == true) {
+                               val uncensored = TextParserState.uncensorText(content)
+                               val pokhwal = PokhwalishAlphabet.pokhwalToFontAlphabet(uncensored)
+                               val recensored = TextParserState.censorText(pokhwal)
+                               "<span class=\"lang-pokhwal\">$recensored</span>"
+                       } else if (tagParam?.equals("gothic", ignoreCase = true) == true)
                                "<span class=\"lang-gothic\">$content</span>"
                        else content
                }
@@ -319,7 +324,16 @@ enum class TextParserFormattingTag(val type: TextParserTagType<Unit>) {
                                        |<textarea class="output-box lang-thedish" readonly></textarea>
                                        |</div>
                                """.trimMargin()
-                       } else content
+                       } else if (content.equals("pokhval", ignoreCase = true) || content.equals("pokhwal", ignoreCase = true)) {
+                               """
+                                       |<div class="pokhwal-alphabet-box">
+                                       |<p>Latin Alphabet:</p>
+                                       |<textarea class="input-box" spellcheck="false"></textarea>
+                                       |<p>Pokhwalish Alphabet:</p>
+                                       |<textarea class="output-box lang-pokhwal" readonly></textarea>
+                                       |</div>
+                               """.trimMargin()
+                       } else ""
                }
        ),
        ;
diff --git a/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt b/src/main/kotlin/info/mechyrdia/lore/tylan_language.kt
deleted file mode 100644 (file)
index f4d5395..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-package info.mechyrdia.lore
-
-object TylanAlphabet {
-       private val allowedTranslitCharacters = setOf(
-               ' ', '\r', '\n', '\t',
-               'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y',
-               '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-               '~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+',
-               '[', '{', '}', ']', '\\', '|', '/', '<',
-               '.', ',', ':', ';', '\'', '"', '?', '>',
-       )
-       
-       private val replacements = listOf(
-               Regex("([0-9xy]+)(?![\\s0-9xy])") to "$1 ",
-               Regex("(?<![\\s0-9xy])([0-9xy]+)") to " $1",
-               
-               Regex("([a-pr-v'])m(?![\\w'])") to "$1A",
-               Regex("([a-pr-v'])n(?![\\w'])") to "$1E",
-               Regex("([a-ps-v'])r(?![\\w'])") to "$1H",
-               Regex("([ac-fh-jl-or-v'])s(?![\\w'])") to "$1I",
-               Regex("([a-pr-v'])t(?![\\w'])") to "$1Q",
-               
-               Regex("x") to "M",
-               Regex("y") to "N",
-               Regex("[qw-z]") to "",
-               
-               Regex("ch") to "C",
-               Regex("dh") to "D",
-               Regex("sh") to "S",
-               Regex("th") to "T",
-               
-               Regex("bs") to "B",
-               Regex("gs") to "G",
-               Regex("ks") to "K",
-               Regex("ps") to "P",
-               
-               Regex("b'([Is])") to "b$1",
-               Regex("g'([Is])") to "g$1",
-               Regex("k'([Is])") to "k$1",
-               Regex("p'([Is])") to "p$1",
-               
-               Regex("ff") to "F",
-               Regex("fv") to "V",
-               Regex("hj") to "J",
-               Regex("lh") to "L",
-               Regex("ll") to "L",
-               Regex("hl") to "L",
-               Regex("rh") to "R",
-               Regex("rr") to "R",
-               Regex("hr") to "R",
-               Regex("d'h") to "dh",
-               Regex("l'h") to "lh",
-               Regex("l'J") to "lJ",
-               Regex("r'h") to "rh",
-               Regex("r'J") to "rJ",
-               Regex("s'h") to "sh",
-               Regex("t'h") to "th",
-               Regex("h'l") to "hl",
-               Regex("h'r") to "hr",
-               Regex("B'h") to "Bh",
-               Regex("G'h") to "Gh",
-               Regex("K'h") to "Kh",
-               Regex("P'h") to "Ph",
-               Regex("c(?!h)") to "",
-               
-               Regex("ae") to "W",
-               Regex("au") to "X",
-               Regex("ea") to "Y",
-               Regex("ei") to "Z",
-               Regex("eo") to "w",
-               Regex("eu") to "x",
-               Regex("oa") to "y",
-               Regex("ou") to "z",
-               Regex("oe") to "O",
-               Regex("ui") to "U",
-               
-               Regex("i([aeiouOUw-zW-Z])") to "ij$1",
-               Regex("^([aeiouOUw-zW-Z])") to "'$1",
-               Regex("([^'BCDFGJKLPR-TVbdf-hj-npr-tv])([aeiouOUw-zW-Z])") to "$1'$2",
-               Regex("([aeiouOUw-zW-Z])([aeiouOUw-zW-Z])") to "$1'$2",
-       )
-       
-       fun tylanToFontAlphabet(tylan: String) = replacements.fold(tylan.lowercase().filter { it in allowedTranslitCharacters }) { partial, (regex, replacement) ->
-               partial.replace(regex, replacement)
-       }
-}
diff --git a/src/main/resources/static/font/pokhval-alphabet.woff b/src/main/resources/static/font/pokhval-alphabet.woff
new file mode 100644 (file)
index 0000000..2fa7d67
Binary files /dev/null and b/src/main/resources/static/font/pokhval-alphabet.woff differ
index 5b733e6b0895f338e2a4abdd58be1f76e19cd274..4acac5189e4e74c98f3b47a54aaacf65ae7f6501 100644 (file)
                }
        });
 
+       window.addEventListener("load", function () {
+               // Pokhwalish alphabet
+               async function pokhwalToFont(input, output) {
+                       const inText = input.value;
+                       const outText = await (await fetch('/pokhwal-lang', {
+                               method: 'POST',
+                               headers: {
+                                       'Content-Type': 'text/plain',
+                               },
+                               body: inText,
+                       })).text();
+
+                       if (inText === input.value)
+                               output.value = outText;
+               }
+
+               const pokhwalAlphabetBoxes = document.getElementsByClassName("pokhwal-alphabet-box");
+               for (const pokhwalAlphabetBox of pokhwalAlphabetBoxes) {
+                       const inputBox = pokhwalAlphabetBox.getElementsByClassName("input-box")[0];
+                       const outputBox = pokhwalAlphabetBox.getElementsByClassName("output-box")[0];
+
+                       inputBox.addEventListener("input", () => pokhwalToFont(inputBox, outputBox));
+               }
+       });
+
        window.addEventListener("load", function () {
                // Preview themes
                const themeChoices = document.getElementsByName("theme");
index 831710e1c8c5d4f5ce3ebac2c9fc28a02849391d..acf0abaeaae4378c28198e430d21868f3a962db0 100644 (file)
@@ -902,6 +902,24 @@ textarea.lang-thedish {
        line-height: 1.0;
 }
 
+@font-face {
+       font-family: 'Pochvalsk';
+       src: url(/static/font/pokhval-alphabet.woff) format('woff');
+}
+
+.lang-pokhwal {
+       font-family: Pochvalsk, monospace;
+       font-size: 1em;
+       line-height: 1.0;
+       font-variant: normal !important;
+}
+
+textarea.lang-pokhwal {
+       font-family: Pochvalsk, monospace;
+       font-size: 2em;
+       line-height: 1.0;
+}
+
 #thumb-view {
        display: none;
 }