Created
April 13, 2016 07:20
-
-
Save jujhars13/a038872de2697f26cdebdeb42e5c6365 to your computer and use it in GitHub Desktop.
Ancient Gurmukhi to English transliterator written in EvB
This file contains hidden or 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
| 'original version by Tarsem Singh of STTM | |
| Attribute VB_Name = "Module1" | |
| Private Function convertedChar(AscID) As String | |
| 'Debug.Print Chr(AscID) & "=" & AscID | |
| Select Case AscID | |
| Case 32: convertedChar = " " | |
| Case 48: convertedChar = "0" | |
| Case 49: convertedChar = "1" | |
| Case 50: convertedChar = "2" | |
| Case 51: convertedChar = "3" | |
| Case 52: convertedChar = "4" | |
| Case 53: convertedChar = "5" | |
| Case 54: convertedChar = "6" | |
| Case 55: convertedChar = "7" | |
| Case 56: convertedChar = "8" | |
| Case 57: convertedChar = "9" | |
| Case 58: convertedChar = ":" | |
| Case 59: convertedChar = ";" | |
| Case 60: convertedChar = "ik o" | |
| Case 62: convertedChar = "(n)kaar" | |
| Case 65: convertedChar = "a" | |
| Case 66: convertedChar = "bh" | |
| Case 67: convertedChar = "shh" | |
| Case 68: convertedChar = "dhh" | |
| Case 69: convertedChar = "ou" | |
| Case 70: convertedChar = "dt" | |
| Case 71: convertedChar = "gh" | |
| Case 73: convertedChar = "[ee]" | |
| Case 74: convertedChar = "jh" | |
| Case 75: convertedChar = "kh" | |
| Case 76: convertedChar = "l" | |
| Case 77: convertedChar = "n" | |
| Case 80: convertedChar = "f" | |
| Case 81: convertedChar = "thh" | |
| Case 82: convertedChar = "r" | |
| Case 83: convertedChar = "sh" | |
| Case 84: convertedChar = "th" | |
| Case 85: convertedChar = "[oo]" | |
| Case 86: convertedChar = "rr" | |
| Case 87: convertedChar = "[aa(n)]" | |
| Case 88: convertedChar = "y" | |
| Case 89: convertedChar = "[ai]" | |
| Case 90: convertedChar = "gh" | |
| Case 92: convertedChar = "nj" | |
| Case 93: convertedChar = "||" | |
| Case 94: convertedChar = "khh" | |
| Case 97: convertedChar = "ou" | |
| Case 98: convertedChar = "b" | |
| Case 99: convertedChar = "ch" | |
| Case 100: convertedChar = "dh" | |
| Case 101: convertedChar = "e" | |
| Case 102: convertedChar = "dd" | |
| Case 103: convertedChar = "g" | |
| Case 104: convertedChar = "h" | |
| Case 105: convertedChar = "[i]" | |
| Case 106: convertedChar = "j" | |
| Case 107: convertedChar = "k" | |
| Case 108: convertedChar = "l" | |
| Case 109: convertedChar = "m" | |
| Case 110: convertedChar = "n" | |
| Case 111: convertedChar = "[o]" | |
| Case 112: convertedChar = "p" | |
| Case 113: convertedChar = "t" | |
| Case 114: convertedChar = "r" | |
| Case 115: convertedChar = "s" | |
| Case 116: convertedChar = "tt" | |
| Case 117: convertedChar = "[u]" | |
| Case 118: convertedChar = "v" | |
| Case 119: convertedChar = "[aa]" | |
| Case 120: convertedChar = "n" | |
| Case 121: convertedChar = "[ae]" | |
| Case 122: convertedChar = "z" | |
| Case 124: convertedChar = "ng" | |
| Case 131: convertedChar = "noo" | |
| Case 174: convertedChar = "r" | |
| Case 181: convertedChar = "n" | |
| ' Case Else: convertedChar = "" | |
| End Select | |
| End Function | |
| Public Function convChars(str) | |
| Dim i As Integer | |
| Dim ch As String | |
| Dim conv As String | |
| Dim Prevconv As String | |
| Dim PPrevconv As String | |
| Dim stemp As String | |
| Dim sNNext As String | |
| Dim B | |
| Dim iNextAsc As Integer | |
| Dim iThisAsc As Integer | |
| For i = 1 To Len(str) | |
| ch = Mid(str, i, 1) | |
| ' If ch = " " Then | |
| ' Label1 = Label1 & " " | |
| ' Else | |
| ' Label1 = Label1 & Asc(ch) & "," | |
| ' End If | |
| iThisAsc = Asc(ch) | |
| If iThisAsc > 31 Or iThisAsc < 182 Then | |
| conv = convertedChar(iThisAsc) | |
| Else | |
| conv = "" | |
| End If | |
| If (conv = "[ai]" Or conv = "[aa]") And Right(convChars, 1) = "a" Then | |
| ' Remove the airaa if it is before vowels | |
| convChars = Left(convChars, Len(convChars) - 1) | |
| End If | |
| If conv = "[ee]" And Right(convChars, 1) = "e" Then | |
| ' Remove the eeree if it is before vowels | |
| convChars = Left(convChars, Len(convChars) - 1) | |
| End If | |
| If conv = "[u]" And Right(convChars, 1) = "u" Then | |
| ' Remove the extendchar if it is before vowels | |
| convChars = Left(convChars, Len(convChars) - 1) | |
| End If | |
| If conv = "[oo]" And Right(convChars, 2) = "ou" Then | |
| ' Remove the extendchar if it is before vowels | |
| convChars = Left(convChars, Len(convChars) - 2) | |
| End If | |
| If Right(convChars, 3) = "[i]" And Not B And Left(conv, 1) <> "[" Then | |
| ' Shift the sihaaree translit one to the right | |
| convChars = Left(convChars, Len(convChars) - 3) & conv & "[i]" | |
| ' Shift the next one too if it is a raaraa in the pehr | |
| If i < Len(str) Then | |
| B = Asc(Mid(str, i + 1, 1)) <> 82 | |
| Else | |
| B = False | |
| End If | |
| ElseIf conv = " " Then | |
| If Right(convChars, 3) = "[i]" And Prevconv <> "h" Then | |
| convChars = Left(convChars, Len(convChars) - 3) & conv | |
| ElseIf Right(convChars, 3) = "[u]" And PPrevconv <> "h" Then 'And Right(ConvChars, 2) <> "hu" | |
| convChars = Left(convChars, Len(convChars) - 3) & conv | |
| Else | |
| convChars = convChars & " " | |
| End If | |
| Else | |
| convChars = convChars & conv | |
| B = False | |
| End If | |
| If i + 1 <= Len(str) Then | |
| iNextAsc = Asc(Mid(str, i + 1, 1)) | |
| Else | |
| iNextAsc = 0 | |
| End If | |
| stemp = Mid(str, i, 3) | |
| If Len(stemp) = 3 Then | |
| sNNext = Right(stemp, 1) | |
| Else | |
| sNNext = "" | |
| End If | |
| convChars = convChars & extendIt(Right(convChars, 1), conv, iThisAsc, iNextAsc, Mid(str, i + 1, 1), sNNext) | |
| PPrevconv = Prevconv | |
| Prevconv = conv | |
| Next | |
| 'ConvChars = UCase(ConvChars) | |
| End Function | |
| Private Function extendIt(EndChar, convChars, ThisAsc, NextAsc, NextConvChars, NNextChar) As String | |
| On Error Resume Next | |
| If NextConvChars <> "" Then | |
| NextConvChars = convertedChar(Asc(NextConvChars)) | |
| ' ignore tipee and || and if next char a raaraa in pehr | |
| 'space, raaraa, raaraa, tippee, ?,eeree | |
| If NextAsc = 10 Or NextAsc = 13 Then | |
| extendIt = vbCrLf | |
| Else | |
| If EndChar <> "]" And convChars <> " " And (Right(NextConvChars, 1) <> "]" Or NextAsc = 105) And NextAsc <> 32 And NextAsc <> 82 And NextAsc <> 174 And ThisAsc <> 77 And ThisAsc <> 93 And ThisAsc <> 181 And ThisAsc <> 65 And ThisAsc <> 69 And NextAsc <> 69 And NextAsc <> 97 And NextAsc <> 101 And Not IsNumeric(Chr(ThisAsc)) Then extendIt = "a" | |
| ' Make it "a" if the next char is a [i] (words like har etc) | |
| 'by jujhar If extendIt = "u" And NextAsc = 105 Then extendIt = "a" | |
| 'If extendIt = "u" Then extendIt = "a" 'try to get all u's to an "a" | |
| If extendIt <> "" And NNextChar <> "" Then | |
| If (NextAsc = 104 And Asc(NNextChar) <> 117) Or (NextAsc = 105 And Asc(NNextChar) = 104) Then extendIt = "e" | |
| End If | |
| End If | |
| Debug.Print extendIt | |
| End If | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment