Skip to content

Commit

Permalink
urdu
Browse files Browse the repository at this point in the history
Signed-off-by: Finbarrs Oketunji <[email protected]>
  • Loading branch information
0xnu committed Apr 20, 2024
1 parent 0870417 commit 4a62fbb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog

## 1.0.3 - 2024-04-20
* Urdu Phonetic Patterns

## 1.0.2 - 2024-04-20
* Hindi Phonetic Patterns

## 1.0.1 - 2024-04-19
* Enhanced for Yoruba, Igbo and Hausa names

## 1.0.0 - 2024-04-19
* Initial Release
* Initial Release
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
"Obinwanne Obiora", // Igbo
"Abdussalamu Abubakar", // Hausa
"Virat Kohli", // Hindi
"Usman Shah", // Urdu
}

// Encode each name using NYSIIS
Expand Down Expand Up @@ -83,4 +84,4 @@ This project is licensed under the [MIT License](./LICENSE).

(c) 2024 [Finbarrs Oketunji](https://finbarrs.eu).

[NPM](https://www.npmjs.com/package/nysiis)
[NPM](https://www.npmjs.com/package/nysiis)
20 changes: 17 additions & 3 deletions nysiis.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ func (n *Nysiis) translateFirstCharacters(name string) string {
name = "F" + name[2:] // Hindi: 'Ph' -> 'F'
case strings.HasPrefix(name, "TH"):
name = "T" + name[2:] // Hindi: 'Th' -> 'T'
case strings.HasPrefix(name, "CH"):
name = "C" + name[2:] // Urdu: 'Ch' -> 'C'
case strings.HasPrefix(name, "GH"):
name = "G" + name[2:] // Urdu: 'Gh' -> 'G'
case strings.HasPrefix(name, "KH"):
name = "K" + name[2:] // Urdu: 'Kh' -> 'K'
case strings.HasPrefix(name, "SH"):
name = "S" + name[2:] // Urdu: 'Sh' -> 'S'
case strings.HasPrefix(name, "ZH"):
name = "J" + name[2:] // Urdu: 'Zh' -> 'J'
}
return name
}
Expand Down Expand Up @@ -140,21 +150,25 @@ func (n *Nysiis) translateChar(char rune, name string, i int) rune {
} else if char == 'T' && i+1 < len(name) && name[i+1] == 'S' {
char = 'S' // Yoruba: 'Ts' -> 'S'
} else if char == 'S' && i+1 < len(name) && name[i+1] == 'H' {
char = 'S' // Hausa: 'Sh' -> 'S'
char = 'S' // Hausa, Urdu: 'Sh' -> 'S'
} else if char == 'B' && i+1 < len(name) && name[i+1] == 'H' {
char = 'B' // Hindi: 'Bh' -> 'B'
} else if char == 'D' && i+1 < len(name) && name[i+1] == 'H' {
char = 'D' // Hindi: 'Dh' -> 'D'
} else if char == 'G' && i+1 < len(name) && name[i+1] == 'H' {
char = 'G' // Hindi: 'Gh' -> 'G'
char = 'G' // Hindi, Urdu: 'Gh' -> 'G'
} else if char == 'J' && i+1 < len(name) && name[i+1] == 'H' {
char = 'J' // Hindi: 'Jh' -> 'J'
} else if char == 'K' && i+1 < len(name) && name[i+1] == 'H' {
char = 'K' // Hindi: 'Kh' -> 'K'
char = 'K' // Hindi, Urdu: 'Kh' -> 'K'
} else if char == 'P' && i+1 < len(name) && name[i+1] == 'H' {
char = 'F' // Hindi: 'Ph' -> 'F'
} else if char == 'T' && i+1 < len(name) && name[i+1] == 'H' {
char = 'T' // Hindi: 'Th' -> 'T'
} else if char == 'C' && i+1 < len(name) && name[i+1] == 'H' {
char = 'C' // Urdu: 'Ch' -> 'C'
} else if char == 'Z' && i+1 < len(name) && name[i+1] == 'H' {
char = 'J' // Urdu: 'Zh' -> 'J'
}

return char
Expand Down
5 changes: 5 additions & 0 deletions nysiis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestNysiis_Encode(t *testing.T) {
encodedName7 := nysiis.NewNysiis().Encode(name7)
fmt.Printf("Encoded name for %q: %s\n", name7, encodedName7)

name8 := "Usman Shah"
encodedName8 := nysiis.NewNysiis().Encode(name8)
fmt.Printf("Encoded name for %q: %s\n", name8, encodedName8)

// Output:
// Encoded name for "Watkins": WATCAN
// Encoded name for "Robert Johnson": RABART
Expand All @@ -44,4 +48,5 @@ func TestNysiis_Encode(t *testing.T) {
// Encoded name for "Obinwanne Obiora": OBAWAN
// Encoded name for "Abdussalamu Abubakar": ABDASA
// Encoded name for "Virat Kohli": VARATC
// Encoded name for "Usman Shah": USNANS
}

0 comments on commit 4a62fbb

Please sign in to comment.