Skip to content

Commit

Permalink
Handle Arabic Thousands
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifnimah committed Jul 23, 2023
1 parent 00ee51a commit 0678a1f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
23 changes: 16 additions & 7 deletions NumToWords/EntryAr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func (Entry *EntryAr) Translate(Input int) string {
{
Result = Entry.handleHundreds(Input)
}
//case Input < 100000: //1000-9999
// {
// Result = Entry.handleTeens(Input)
// }
case Input < 100000: //1000-9999
{
Result = Entry.handleThousands(Input)
}
}

//if Input < 10 {
Expand Down Expand Up @@ -83,12 +83,21 @@ func (EntAr EntryAr) handleTwenties(Input int) string {
func (EntAr EntryAr) handleHundreds(Input int) string {
And := ""
Seg01 := EntAr.LocalizedEntity.Hundreds[(Input / 100)]
//Seg02 := EntAr.LocalizedEntity.Hundred
Seg03 := EntAr.Translate(Input % 100)
if Seg01 != "" && Seg03 != "" {
Seg02 := EntAr.Translate(Input % 100)
if Seg01 != "" && Seg02 != "" {
And = EntAr.LocalizedEntity.And
}

return fmt.Sprintf("%s %s %s", Seg01, And, Seg02)
}

func (EntAr EntryAr) handleThousands(Input int) string {
And := ""
Seg01 := EntAr.LocalizedEntity.Thousands[(Input / 1000)]
Seg03 := EntAr.Translate(Input % 1000)
if Seg01 != "" && Seg03 != "" {
And = EntAr.LocalizedEntity.And
}
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

Expand Down
23 changes: 12 additions & 11 deletions NumToWords/locales/Lang.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package locales

type Lang struct {
Units []string
Teens []string
Tens []string
Hundreds []string
And string
Zero string
Hundred string
Thousand string
Million string
Billion string
Trillion string
Units []string
Teens []string
Tens []string
Hundreds []string
Thousands []string
And string
Zero string
Hundred string
Thousand string
Million string
Billion string
Trillion string
}
21 changes: 11 additions & 10 deletions NumToWords/locales/ar.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package locales

var AR = Lang{
Units: []string{"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Teens: []string{"عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"},
Tens: []string{"", "", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"},
Hundreds: []string{"", "مئة", "مئتان", "ثلاث مئة", "اربع مئة", "خمس مئة", "ست مئة", "سبع مئة", "ثمان مئة", "تسع مئة"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الف",
Million: "مليون",
Billion: "مليار",
Units: []string{"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Teens: []string{"عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"},
Tens: []string{"", "", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"},
Hundreds: []string{"", "مئة", "مئتان", "ثلاثمئة", "اربعمئة", "خمسمئة", "ستمئة", "سبعمئة", "ثمانمئة", "تسعمئة"},
Thousands: []string{"", "ألف", "ألفان", "ثلاثة آلاف", "اربعة آلاف", "خمسة آلاف", "ستة آلاف", "سبعة آلاف", "ثمانية آلاف", "تسعة آلاف"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الف",
Million: "مليون",
Billion: "مليار",
}
2 changes: 1 addition & 1 deletion _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
input := 656
input := 9824
words, err := NumToWords.Convert(input, "ar")
if err != nil {
return
Expand Down

0 comments on commit 0678a1f

Please sign in to comment.