Skip to content

Commit

Permalink
Merge pull request #3 from yousifnimah/dev
Browse files Browse the repository at this point in the history
Dev - support Billions in Arabic lang
  • Loading branch information
yousifnimah authored Jul 23, 2023
2 parents 603ea29 + 27629fb commit ca07e3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions NumToWords/EntryAr.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func (Entry *EntryAr) Translate(Input int) string {
{
Result = Entry.handleMillions(Input)
}
case Input < 1000000000000: //1000000000-9999999999
{
Result = Entry.handleBillions(Input)
}
}

//if Input < 10 {
Expand Down Expand Up @@ -143,6 +147,16 @@ func (EntAr EntryAr) handleMillions(Input int) string {
return fmt.Sprintf("%s %s %s", Seg01, And, Seg03)
}

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

func (Entry EntryAr) ZeroResponse() string {
return Entry.LocalizedEntity.Zero
}
1 change: 1 addition & 0 deletions NumToWords/locales/Lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Lang struct {
TenThousands []string
HundredThousands []string
Millions []string
Billions []string
And string
Zero string
Hundred string
Expand Down
1 change: 1 addition & 0 deletions NumToWords/locales/ar.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var AR = Lang{
TenThousands: []string{"", "عشرة آلاف", "عشرون الف", "ثلاثون الف", "اربعون الف", "خمسون الف", "ستون الف", "سبعون الف", "ثمانون الف", "تسعون الف"},
HundredThousands: []string{"", "مئة الف", "مئتان الف", "ثلاثمئة الف", "اربعمئة الف", "خمسمئة الف", "ستمئة الف", "سبعمئة الف", "ثمانمئة الف", "تسعمئة الف"},
Millions: []string{"", "مليون", "مليونين", "ثلاثة ملايين", "اربعة ملايين", "خمسة ملايين", "ستة ملايين", "سبعة ملايين", "ثمانية ملايين", "تسعة ملايين"},
Billions: []string{"", "مليار", "ملياران", "ثلاثة مليارات", "اربعة مليارات", "خمسة مليارات", "ستة مليارات", "سبعة مليارات", "ثمانية مليارات", "تسعة مليارات"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Expand Down
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 := 901511
input := 1000010012
words, err := NumToWords.Convert(input, "ar")
if err != nil {
return
Expand Down

0 comments on commit ca07e3a

Please sign in to comment.