Created
December 23, 2021 01:47
-
-
Save elsanussi-s-mneina/58d38188bb7137dea159527f9e68280c to your computer and use it in GitHub Desktop.
A single page web application for converting from Arabic script to Old South Arabian script. part of a video on my Youtube channel.
This file contains 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
<!DOCTYPE html> | |
<!-- | |
MIT License | |
Copyright (c) 2021 Elsanussi Mneina | |
https://github.com/elsanussi-s-mneina | |
https://www.linkedin.com/in/elsanussi-mneina-57a8181b5/ | |
elsanussi.m@outlook.com | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
--> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> | |
<title>Arabic to Old South Arabian Script Transliterator</title> | |
<script> | |
var EXAMPLE_TEXT = 'شُكْرًا جَزِيْلًا \n تُوْجَدْ شَدَّةٌ، وَفَتْحَةٌ عَلَى هَٰذِهِ ٱلوَرَقَةٍ '; | |
function transliterate(inputString) | |
{ | |
return arabicSouthArabianTranslit.transliterate(inputString); | |
} | |
function transliterateEventHandler() | |
{ | |
var inputText = document.getElementById('arabicInputTextArea').value; | |
var outputText = transliterate(inputText); | |
document.getElementById('arabicOutputTextArea').value = outputText; | |
} | |
function placeExampleTextEventHandler() | |
{ | |
document.getElementById('arabicInputTextArea').value = EXAMPLE_TEXT; | |
} | |
</script> | |
<script src="translitAS.js"></script> | |
</head> | |
<body> | |
<h1>Arabic to Old South Arabian Script Transliterator: <span lang="ar"> تغيير الخط إلى المسند </span></h1> | |
<div role="form"> | |
<label for="arabicInputTextArea"><h2>Input: <span lang="ar">المعطيات</span></h2></label> | |
<p>Paste or type Arabic text in the following text input area: ضع النص في الصندوق التالي | |
<br> | |
<button onclick="placeExampleTextEventHandler();">Put Example ضِعْ مَثَلًا</button> | |
</p> | |
<textarea id="arabicInputTextArea" rows="4" cols="100" lang="ar" aria-live="assertive"></textarea> | |
<h2>Actions أوامر</h2> | |
<button onclick="transliterateEventHandler();">Transliterate حوّل النص إلى المسند</button> | |
<label for="arabicOutputTextArea"><h2>Results النتيجة</h2></label> | |
<textarea id="arabicOutputTextArea" rows="4" cols="100" lang="ar" aria-live="assertive"></textarea> | |
</div> | |
<footer><a href="https://github.com/elsanussi-s-mneina/">Elsanussi Mneina made this page. صنع هذه الصفحة السنوسي امنينة </a> | |
</footer> | |
</body> | |
</html> |
This file contains 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
package main | |
import "syscall/js" | |
import "fmt" | |
import "strings" | |
var transliterationTable = [][2]string { | |
{"ه", | |
"𐩠"}, | |
{"ل", | |
"𐩡"}, | |
{"ح", | |
"𐩢"}, | |
{"م", | |
"𐩣"}, | |
{"ق", | |
"𐩤"}, | |
{"و", | |
"𐩥"}, | |
{"ش", | |
"𐩦"}, | |
{"ر", | |
"𐩧"}, | |
{"ب", | |
"𐩨"}, | |
{"ت", | |
"𐩩"}, | |
{"س", | |
"𐩪"}, | |
{"ك", | |
"𐩫"}, | |
{"ن", | |
"𐩬"}, | |
{"خ", | |
"𐩭"}, | |
{"ص", | |
"𐩮"}, | |
{"س", | |
"𐩯"}, | |
{"ف", | |
"𐩰"}, | |
{"ا", | |
"𐩱"}, | |
{"ع", | |
"𐩲"}, | |
{"ض", | |
"𐩳"}, | |
{"ج", | |
"𐩴"}, | |
{"د", | |
"𐩵"}, | |
{"غ", | |
"𐩶"}, | |
{"ط", | |
"𐩷"}, | |
{"ز", | |
"𐩸"}, | |
{"ذ", | |
"𐩹"}, | |
{"ي", | |
"𐩺"}, | |
{"ث", | |
"𐩻"}, | |
{"ظ", | |
"𐩼"}, | |
// The following characters | |
// are not strictly part of | |
// the Arabic alphabet, but | |
// they are official parts | |
// of the Arabic script. | |
{"ة", | |
"𐩠"}, | |
{"ى", | |
"𐩺"}, | |
{"أ", | |
"𐩱"}, | |
{"إ", | |
"𐩱"}, | |
{"آ", | |
"𐩱"}, | |
{"ٱ", | |
"𐩱"}, | |
{"ؤ", | |
"𐩥"}, | |
{"ئ", | |
"𐩺"}, | |
} | |
func main() { | |
println("Transliteration software for converting from Arabic script to South Arabian script loaded") | |
js.Global().Set("arabicSouthArabianTranslit", map[string]interface{}{"transliterate": transliterateArabicToSouthArabian}) | |
fmt.Println("Program ended normally", transliterateArabicToSouthArabian("ابتثجحخدذرزسشصضطظعغفقكلمنهوي")) | |
} | |
func getFirstRuneAsString(text string) string { | |
var allRunes []rune = []rune(text) | |
var firstRune rune | |
if len(allRunes) > 0 { | |
firstRune = allRunes[0] | |
} | |
return string(firstRune) | |
} | |
func findPrefixMatchInTable(text string) (bool, string, string) { | |
var hasMatch bool | |
var matchSource string | |
var matchDestination string | |
for _, row := range transliterationTable { | |
if strings.HasPrefix(text, row[0]) { | |
hasMatch = true | |
matchSource = row[0] | |
matchDestination = row[1] | |
break | |
} | |
} | |
return hasMatch, matchSource, matchDestination | |
} | |
func transliterateArabicToSouthArabian(arabicText string) string { | |
var southArabian string | |
for len(arabicText) > 0 { | |
var startOfArabicText string = getFirstRuneAsString(arabicText) | |
var hasMatch bool | |
var theMatchArabic string | |
var theMatchSouthArabian string | |
hasMatch, theMatchArabic, theMatchSouthArabian = findPrefixMatchInTable(arabicText) | |
if hasMatch { | |
southArabian += theMatchSouthArabian | |
arabicText = strings.TrimPrefix(arabicText, theMatchArabic) | |
} else { | |
// Copy the first character over, as is, no transliteration necessary. | |
southArabian += startOfArabicText | |
arabicText = strings.TrimPrefix(arabicText, startOfArabicText) | |
} | |
} | |
return southArabian | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment