Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elsanussi-s-mneina/04e6d7958f15078c595945b67d6b78ad to your computer and use it in GitHub Desktop.
Save elsanussi-s-mneina/04e6d7958f15078c595945b67d6b78ad to your computer and use it in GitHub Desktop.
Converts Armenian Script to Arabic based on a system I invented 2 hours ago. Transliteration system not intended to be very sophisticated. This uses GopherJS, and can run in the browser.
// This code runs using GopherJS. It was
// programmed and demonstrated on the gopherJS playground,
// at https://gopherjs.github.io/playground/
// This is a demonstration program for Arabic to Armenian transliteration.
// It can also be used to demonstrate Go programming language, GopherJS,
// And GopherJS playground. You can watch educational videos on my
// YouTube channel.
/*
Copyright 2021 Elsanussi Mneina youtube.com/GrassDewMorning
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.
*/
package main
import (
"fmt"
"strings"
)
import "syscall/js"
const IGNORE_UNRECOGNIZED_RUNES bool = false
func getFirstRuneAsString(text string) string {
textAsRunes := []rune(text)
firstRune := textAsRunes[0]
return string(firstRune)
}
const ARMENIAN_COLUMN = 0
const ARABIC_COLUMN = 1
// The first column contains an uppercase Armenian letter.
// The second column contains the corresponding lowercase Armenian letter.
// The third column contains the Arabic text that both the uppercase and lowercase Armenian letters will become
// as part of transliterating.
var threeColumnTransliterationChart [][3]string = [][3]string{
{"Ա", "ա", "ا"},
{"Բ", "բ", "ب"},
{"Գ", "գ", "ج"},
{"Դ", "դ", "د"},
{"Ե", "ե", "ي"},
{"Զ", "զ", "ز"},
{"Է", "է", "ے"},
{"Ը", "ը", "ئ"},
{"Թ", "թ", "تھ"},
{"Ժ", "ժ", "ژ"},
{"Ի", "ի",
"ِ"},
{"Լ", "լ", "ل"},
{"Խ", "խ", "خ"},
{"Ծ", "ծ", "ص"},
{"Կ", "կ", "ك"},
{"Հ", "հ", "ه"},
{"Ձ", "ձ", "ض"},
{"Ղ", "ղ", "غ"},
{"Ճ", "ճ", "چ"},
{"Մ", "մ", "م"},
{"Յ", "յ", "يِ"},
{"Ն", "ն", "ن"},
{"Շ", "շ", "ش"},
{"Ո", "ո", "ۆ"},
{"Չ", "չ", "چ"},
{"Պ", "պ", "پ"},
{"Ջ", "ջ", "ج"},
{"Ռ", "ռ", "ر"},
{"Ս", "ս", "س"},
{"Վ", "վ", "ڤ"},
{"Տ", "տ", "ت"},
{"Ր", "ր", "ڑ"},
{"Ց", "ց", "ص"},
{"Ւ", "ւ", "و"},
{"Փ", "փ",
"پھ"},
{"Ք", "ք", "کھ"},
{"Օ", "օ", "ۆ"},
{"Ֆ", "ֆ", "ف"},
{"ու", "ու", "ُ"},
{"և", "և", "ىڤ"},
}
func createTwoColumnTransliterationChart(threeColumn [][3]string) [][2]string {
var twoColumn [][2]string = [][2]string{}
for _, row := range threeColumn {
var capitalRow = [2]string{row[0], row[2]}
twoColumn = append(twoColumn, capitalRow)
var smallRow = [2]string{row[1], row[2]}
twoColumn = append(twoColumn, smallRow)
}
return twoColumn
}
func main() {
fmt.Println(
"Transliterating Armenian Script to Arabic Script")
var armenianText string
// Get user input
armenianText = "Աա 232 Բբ" // example text
armenianText = js.Global().Call("prompt", "Type Armenian Text to be transliterated to Arabic Script:").String()
fmt.Println("You typed the following Armenian text:")
fmt.Println(armenianText)
var arabicText string
var transliterationChart = createTwoColumnTransliterationChart(threeColumnTransliterationChart)
// Ա U+0531
// ա U+0561
// The previous two Armenian letters become Arabic letter alef.
for len(armenianText) > 0 {
var foundMatch bool
for _, row := range transliterationChart {
if strings.HasPrefix(armenianText, row[ARMENIAN_COLUMN]) {
arabicText += row[ARABIC_COLUMN]
foundMatch = true
armenianText = strings.TrimPrefix(armenianText, row[ARMENIAN_COLUMN])
}
if foundMatch {
break
}
}
if !foundMatch {
firstChar := getFirstRuneAsString(armenianText)
armenianText = strings.TrimPrefix(armenianText, firstChar)
if !IGNORE_UNRECOGNIZED_RUNES {
arabicText += firstChar
}
}
}
fmt.Println("The resulting arabic script text is:", arabicText)
js.Global().Call("alert", arabicText)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment