diff --git a/README.md b/README.md index 51f234f..9db214c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# Esperanto alphabet converter +# alfabetoj + +A tool for transliterating Esperanto text into other alphabets ## Links * Homepage: [salif.github.io/alfabetoj](https://salif.github.io/alfabetoj/) -* Source code: [github.com/salif/alfabetoj](https://github.com/salif/alfabetoj) -* Source code: [codeberg.org/salif/alfabetoj](https://codeberg.org/salif/alfabetoj) -* Issues (Github): [github.com/salif/alfabetoj/issues](https://github.com/salif/alfabetoj/issues) -* Issues (Codeberg): [codeberg.org/salif/alfabetoj/issues](https://codeberg.org/salif/alfabetoj/issues) -* Discuss (Github): [github.com/salif/alfabetoj/discussions](https://github.com/salif/alfabetoj/discussions) -* Chat (Element/Matrix): [#salif-alfabetoj:mozilla.org](https://matrix.to/#/#salif-alfabetoj:mozilla.org) +* Source code: [Github](https://github.com/salif/alfabetoj), [Codeberg](https://codeberg.org/salif/alfabetoj) +* Issues: [Github](https://github.com/salif/alfabetoj/issues), [Codeberg](https://codeberg.org/salif/alfabetoj/issues) +* Discuss: [Github](https://github.com/salif/alfabetoj/discussions) +* [Matrix Chat](https://matrix.to/#/#salif-alfabetoj:mozilla.org): #salif-alfabetoj:mozilla.org ## Contributing diff --git a/index.html b/index.html index 085028e..e918765 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ Esperanto alphabet converter - + diff --git a/konvertilo.js b/konvertilo.js index 2fa8967..a10509b 100644 --- a/konvertilo.js +++ b/konvertilo.js @@ -100,6 +100,54 @@ var konvertilo = { "u": "უ", "ŭ": "ჳ", "v": "ვ", "z": "ზ" } }, + armenian: { + to_esperanto: { + "Ա": "A", "Բ": "B", "Ծ": "C", "Ճ": "Ĉ", "Դ": "D", "է": "E", + "Ֆ": "F", "Գ": "G", "Ղ": "Ĝ", "Հ": "H", "Խ": "Ĥ", "Ի": "I", + "Յ": "J", "Ջ": "Ĵ", "Կ": "K", "Լ": "L", "Մ": "M", "Ն": "N", + "Ո": "O", "Պ": "P", "Ր": "R", "Ս": "S", "Շ": "Ŝ", "Տ": "T", + "Ւ": "U", "Ւ": "Ŭ", "Վ": "V", "Զ": "Z", + "ա": "a", "բ": "b", "ծ": "c", "ճ": "ĉ", "դ": "d", "ե": "e", + "ֆ": "f", "գ": "g", "ղ": "ĝ", "հ": "h", "խ": "ĥ", "ի": "i", + "յ": "j", "ջ": "ĵ", "կ": "k", "լ": "l", "մ": "m", "ն": "n", + "ո": "o", "պ": "p", "ր": "r", "ս": "s", "շ": "ŝ", "տ": "t", + "ւ": "u", "ւ": "ŭ", "վ": "v", "զ": "z", + }, + from_esperanto: { + "A": "Ա", "B": "Բ", "C": "Ծ", "Ĉ": "Ճ", "D": "Դ", "E": "է", + "F": "Ֆ", "G": "Գ", "Ĝ": "Ղ", "H": "Հ", "Ĥ": "Խ", "I": "Ի", + "J": "Յ", "Ĵ": "Ջ", "K": "Կ", "L": "Լ", "M": "Մ", "N": "Ն", + "O": "Ո", "P": "Պ", "R": "Ր", "S": "Ս", "Ŝ": "Շ", "T": "Տ", + "U": "Ւ", "Ŭ": "Ւ", "V": "Վ", "Z": "Զ", + "a": "ա", "b": "բ", "c": "ծ", "ĉ": "ճ", "d": "դ", "e": "ե", + "f": "ֆ", "g": "գ", "ĝ": "ղ", "h": "հ", "ĥ": "խ", "i": "ի", + "j": "յ", "ĵ": "ջ", "k": "կ", "l": "լ", "m": "մ", "n": "ն", + "o": "ո", "p": "պ", "r": "ր", "s": "ս", "ŝ": "շ", "t": "տ", + "u": "ւ", "ŭ": "ւ", "v": "վ", "z": "զ" + } + }, + // hebrew: { + // to_esperanto: {}, + // from_esperanto: {} + // }, + // greek: { + // to_esperanto: {}, + // from_esperanto: {} + // }, + korean: { + from_esperanto: { + "A": "ㅏ", "B": "ㅂ", "C": "ㅉ", "Ĉ": "ㅊ", "D": "ㄷ", "E": "ㅔ", + "F": "ㅍ", "G": "ㄱ", "Ĝ": "ㄲ", "H": "ㆆ", "Ĥ": "ㅎ", "I": "ㅣ", + "J": "ㅣ", "Ĵ": "ㅈ", "K": "ㅋ", "L": "ㄹ", "M": "ㅁ", "N": "ㄴ", + "O": "ㅗ", "P": "ㅃ", "R": "ㄹ", "S": "ㅅ", "Ŝ": "ㅆ", "T": "ㅌ", + "U": "ㅜ", "Ŭ": "으", "V": "ㅸ", "Z": "ㅿ", + "a": "ㅏ", "b": "ㅂ", "c": "ㅉ", "ĉ": "ㅊ", "d": "ㄷ", "e": "ㅔ", + "f": "ㅍ", "g": "ㄱ", "ĝ": "ㄲ", "h": "ㆆ", "ĥ": "ㅎ", "i": "ㅣ", + "j": "ㅣ", "ĵ": "ㅈ", "k": "ㅋ", "l": "ㄹ", "m": "ㅁ", "n": "ㄴ", + "o": "ㅗ", "p": "ㅃ", "r": "ㄹ", "s": "ㅅ", "ŝ": "ㅆ", "t": "ㅌ", + "u": "ㅜ", "ŭ": "으", "v": "ㅸ", "z": "ㅿ" + } + }, cyrillic_2: { to_esperanto: { "А": "A", "Б": "B", "Ц": "C", "Ч": "Ĉ", "Д": "D", "Е": "E", @@ -163,29 +211,29 @@ var konvertilo = { }, konverti: (function () { - function convert_replacing(input, skribsistemo) { - var output = input - var entries = Object.entries(skribsistemo) - for (var i = 0; i < entries.length; i++) { - var entry = entries[i] - output = output.replaceAll(entry[0], entry[1]) + function convert_replacing(str_input, obj_skribsistemo) { + var str_output = str_input + var objs_entries = Object.entries(obj_skribsistemo) + for (var num_i = 0; num_i < objs_entries.length; num_i++) { + var objs_entry = objs_entries[num_i] + str_output = str_output.replaceAll(objs_entry[0], objs_entry[1]) } - return output + return str_output } - return function (input, skribsistemo, use_replacing) { - if (input.length == 0) { + return function (str_input, obj_skribsistemo, bool_use_replacing) { + if (str_input.length == 0) { return "" } - if (use_replacing) { - return convert_replacing(input, skribsistemo) + if (bool_use_replacing) { + return convert_replacing(str_input, obj_skribsistemo) } - var output = [] - for (var i = 0; i < input.length; i++) { - var input_char = input.charAt(i) - var output_char = skribsistemo[input_char] - output.push(output_char != undefined ? output_char : input_char) + var strs_output = [] + for (var num_i = 0; num_i < str_input.length; num_i++) { + var str_input_char = str_input.charAt(num_i) + var str_output_char = obj_skribsistemo[str_input_char] + strs_output.push(str_output_char != undefined ? str_output_char : str_input_char) } - return output.join("") + return strs_output.join("") } })() diff --git a/script.js b/script.js index 9e54f9e..c830345 100644 --- a/script.js +++ b/script.js @@ -1,7 +1,7 @@ -var lcl_lang = "en" -var lcl_langs = ["en", "eo", "bg"] +var str_lcl_lang = "en" +var strs_lcl_langs = ["en", "eo", "bg"] -var options_convert = [ +var objs_options_convert = [ { l: { "en": "Esperanto → Cyrillic", "bg": "есперанто → кирилица", "eo": "Esperanto → Cirila" }, s: konvertilo.skribsistemoj.cyrillic.from_esperanto, @@ -52,6 +52,46 @@ var options_convert = [ s: konvertilo.skribsistemoj.georgian.to_esperanto, r: false, }, + { + l: { "en": "Esperanto → Armenian", "bg": "есперанто → арменски", "eo": "Esperanto → Armena" }, + s: konvertilo.skribsistemoj.armenian.from_esperanto, + r: false, + }, + { + l: { "en": "Armenian → Esperanto", "bg": "арменски → есперанто", "eo": "Armena → Esperanto" }, + s: konvertilo.skribsistemoj.armenian.to_esperanto, + r: false, + }, + // { + // l: { "en": "Esperanto → Hebrew", "bg": "есперанто → иврит", "eo": "Esperanto → Hebrea" }, + // s: konvertilo.skribsistemoj.hebrew.from_esperanto, + // r: false, + // }, + // { + // l: { "en": "Hebrew → Esperanto", "bg": "иврит → есперанто", "eo": "Hebrea → Esperanto" }, + // s: konvertilo.skribsistemoj.hebrew.to_esperanto, + // r: false, + // }, + // { + // l: { "en": "Esperanto → Greek", "bg": "есперанто → гръцки", "eo": "Esperanto → Greka" }, + // s: konvertilo.skribsistemoj.greek.from_esperanto, + // r: false, + // }, + // { + // l: { "en": "Greek → Esperanto", "bg": "гръцки → есперанто", "eo": "Greka → Esperanto" }, + // s: konvertilo.skribsistemoj.greek.to_esperanto, + // r: false, + // }, + // { + // l: { "en": "Esperanto → Korean", "bg": "есперанто → корейски", "eo": "Esperanto → Korea" }, + // s: konvertilo.skribsistemoj.korean.from_esperanto, + // r: false, + // }, + // { + // l: { "en": "Korean → Esperanto", "bg": "корейски → есперанто", "eo": "Korea → Esperanto" }, + // s: konvertilo.skribsistemoj.korean.to_esperanto, + // r: false, + // }, { l: { "en": "Esperanto → Cyrillic 2", "bg": "есперанто → кирилица 2", "eo": "Esperanto → Cirila 2" }, s: konvertilo.skribsistemoj.cyrillic_2.from_esperanto, @@ -64,43 +104,39 @@ var options_convert = [ } ] -var selected_convert = options_convert[0] +var obj_selected_convert = objs_options_convert[0] -function _i(o) { - var ro = o[lcl_lang] - if (ro == undefined) { - return "" - } else { - return ro - } +function _i(obj) { + var str_ro = obj[str_lcl_lang] + return str_ro == undefined ? "" : str_ro } -function lcl_page(lang) { - lcl_lang = lang +function lcl_page(str_lang) { + str_lcl_lang = str_lang document.title = _i({ "en": "Esperanto alphabet converter", "bg": "Есперанто конвертор на азбуки", "eo": "Esperanta skribsistema konvertilo" }) - document.documentElement.lang = lcl_lang + document.documentElement.lang = str_lcl_lang } function check_lcl() { - var user_langs = navigator.languages - var site_langs = lcl_langs - for (var i = 0; i < user_langs.length; i++) { - var user_lang = user_langs[i] - if (user_lang === lcl_lang) { - return { yes: false } - } else if (site_langs.indexOf(user_lang) > -1) { - return { yes: true, lang: user_lang } + var strs_user_langs = navigator.languages + var strs_site_langs = strs_lcl_langs + for (var num_i = 0; num_i < strs_user_langs.length; num_i++) { + var str_user_lang = strs_user_langs[num_i] + if (str_user_lang === str_lcl_lang) { + return { is_yes: false } + } else if (strs_site_langs.indexOf(str_user_lang) > -1) { + return { is_yes: true, str_lang: str_user_lang } } } - return { yes: false } + return { is_yes: false } } function load_page() { try { - var lcl_c = check_lcl() - if (lcl_c.yes) { - lcl_page(lcl_c.lang) + var obj_lcl_c = check_lcl() + if (obj_lcl_c.is_yes) { + lcl_page(obj_lcl_c.str_lang) } } catch (err) { } @@ -109,7 +145,7 @@ function load_page() { function build_page() { - var body = document.getElementById("main") + var el_body = document.getElementById("main") var el_title = document.createElement("div") el_title.classList.add("h3") @@ -118,20 +154,20 @@ function build_page() { var el_header = document.createElement("div") el_header.classList.add("p-4") el_header.appendChild(el_title) - body.appendChild(el_header) + el_body.appendChild(el_header) var el_con_langs = document.createElement("div") el_con_langs.classList.add("row") - var create_lang_option = function (o, i, p) { + var create_lang_option = function (obj, num_i, el_p) { var el_lang = document.createElement("input") el_lang.classList.add("btn-check") el_lang.type = "radio" el_lang.name = "lang_o" - el_lang.id = "lang_" + i - el_lang.onchange = function (e) { + el_lang.id = "lang_" + num_i + el_lang.onchange = function (ev) { if (this.checked) { - selected_convert = o + obj_selected_convert = obj if (el_input.value.length == 0) { el_output.value = "" el_input.focus() @@ -146,18 +182,18 @@ function build_page() { var el_lang_label = document.createElement("label") el_lang_label.classList.add("btn", "btn-outline-success") el_lang_label.htmlFor = el_lang.id - el_lang_label.textContent = _i(o.l) + el_lang_label.textContent = _i(obj.l) - p.appendChild(el_lang) - p.appendChild(el_lang_label) + el_p.appendChild(el_lang) + el_p.appendChild(el_lang_label) } - for (var i = 0; i < options_convert.length; i += 2) { + for (var num_i = 0; num_i < objs_options_convert.length; num_i += 2) { var el_con_lang = document.createElement("div") el_con_lang.classList.add("btn-group", "col-auto", "my-1") - create_lang_option(options_convert[i], i, el_con_lang) - create_lang_option(options_convert[i + 1], i + 1, el_con_lang) + create_lang_option(objs_options_convert[num_i], num_i, el_con_lang) + create_lang_option(objs_options_convert[num_i + 1], num_i + 1, el_con_lang) el_con_langs.appendChild(el_con_lang) } @@ -166,7 +202,7 @@ function build_page() { var el_con_control = document.createElement("div") el_con_control.classList.add("mb-3") el_con_control.appendChild(el_con_langs) - body.appendChild(el_con_control) + el_body.appendChild(el_con_control) var el_input = document.createElement("textarea") el_input.classList.add("form-control") @@ -177,7 +213,7 @@ function build_page() { var el_con_input = document.createElement("div") el_con_input.classList.add("mb-3") el_con_input.appendChild(el_input) - body.appendChild(el_con_input) + el_body.appendChild(el_con_input) var el_output = document.createElement("textarea") el_output.classList.add("form-control") @@ -187,7 +223,7 @@ function build_page() { var el_con_output = document.createElement("div") el_con_output.classList.add("mb-3") el_con_output.appendChild(el_output) - body.appendChild(el_con_output) + el_body.appendChild(el_con_output) var el_btn_lcl = document.createElement("select") el_btn_lcl.classList.add("form-select", "mx-1") @@ -195,16 +231,16 @@ function build_page() { el_btn_lcl.style.display = "inline-block" el_btn_lcl.onchange = function () { lcl_page(this.value) - body.innerHTML = "" + el_body.innerHTML = "" build_page() } - for (var i = 0; i < lcl_langs.length; i++) { - var lang = lcl_langs[i] + for (var num_i = 0; num_i < strs_lcl_langs.length; num_i++) { + var str_lang = strs_lcl_langs[num_i] var el_btn_lcl_o = document.createElement("option") - el_btn_lcl_o.value = lang - el_btn_lcl_o.textContent = lang - if (lang === lcl_lang) { + el_btn_lcl_o.value = str_lang + el_btn_lcl_o.textContent = str_lang + if (str_lang === str_lcl_lang) { el_btn_lcl_o.selected = true } el_btn_lcl.appendChild(el_btn_lcl_o) @@ -224,7 +260,9 @@ function build_page() { el_btn_letters.classList.add("btn", "btn-primary", "mx-1") el_btn_letters.value = _i({ "en": "letters", "bg": "букви", "eo": "literoj" }) el_btn_letters.onclick = function () { - el_output.value = Object.entries(selected_convert.s).map(e=>e.join(": ")).join("; ") + el_output.value = Object.entries(obj_selected_convert.s).map(function (e) { + return e.join(": ") + }).join("; ") el_output.focus() } @@ -239,19 +277,19 @@ function build_page() { el_con_b_control.appendChild(el_btn_clear) el_con_b_control.appendChild(el_btn_letters) el_con_b_control.appendChild(el_btn_code) - body.appendChild(el_con_b_control) + el_body.appendChild(el_con_b_control) - function scroll_to_output(elm) { - var rect = elm.getBoundingClientRect() - var view_height = Math.max(document.documentElement.clientHeight, window.innerHeight) - var is_not_visible = rect.bottom < 0 || rect.top - view_height >= 0 + function scroll_to_output(el) { + var dom_rect = el.getBoundingClientRect() + var num_view_height = Math.max(document.documentElement.clientHeight, window.innerHeight) + var is_not_visible = dom_rect.bottom < 0 || dom_rect.top - num_view_height >= 0 if (is_not_visible) { - elm.scrollIntoView(true) + el.scrollIntoView(true) } } function convert() { - el_output.value = konvertilo.konverti(el_input.value, selected_convert.s, selected_convert.r) + el_output.value = konvertilo.konverti(el_input.value, obj_selected_convert.s, obj_selected_convert.r) } }