Skip to content

Commit

Permalink
Arabic
Browse files Browse the repository at this point in the history
  • Loading branch information
yousifnimah committed Jul 23, 2023
1 parent b004ebd commit cc6fd9f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NumToWords/Convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package NumToWords

import (
"errors"
"fmt"
)

type NumToWord struct{}
Expand All @@ -25,6 +26,7 @@ func Convert(Input int, Language string) (string, error) {
Ent.BootstrapLanguage()

if IsZero(Input) {
fmt.Println("Input")
return Ent.ZeroResponse(), nil
}

Expand Down
35 changes: 31 additions & 4 deletions NumToWords/EntryAr.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
package NumToWords

import "github.com/yousifnimah/NumToWordsGo/NumToWords/locales"
import (
"fmt"
"github.com/yousifnimah/NumToWordsGo/NumToWords/locales"
"strings"
)

type EntryAr struct {
Language string
LocalizedEntity locales.Lang
}

func (Entry *EntryAr) Translate(i int) string {
//TODO implement me
panic("implement me")
func (Entry *EntryAr) Translate(Input int) string {
And := ""
result := ""
if Input < 10 {
result = Entry.LocalizedEntity.Units[Input]
} else if Input < 20 {
result = Entry.LocalizedEntity.Teens[Input-10]
} else if Input < 100 {
Seg01 := Entry.Translate(Input % 10)
Seg02 := Entry.LocalizedEntity.Tens[Input/10]
if Seg01 != "" && Seg02 != "" {
And = Entry.LocalizedEntity.And
}
result = fmt.Sprintf("%s %s %s", Seg01, And, Seg02)
} else if Input < 1000 {
result = fmt.Sprintf("%s %s %s", Entry.Translate(Input/100), Entry.LocalizedEntity.Hundred, Entry.Translate(Input%100))
} else if Input < 1000000 {
result = fmt.Sprintf("%s %s %s", Entry.Translate(Input/1000), Entry.LocalizedEntity.Thousand, Entry.Translate(Input%1000))
} else if Input < 1000000000 {
result = fmt.Sprintf("%s %s %s", Entry.Translate(Input/1000000), Entry.LocalizedEntity.Million, Entry.Translate(Input%1000000))
} else if Input < 10000000000 {
result = fmt.Sprintf("%s %s %s", Entry.Translate(Input/1000000000), Entry.LocalizedEntity.Billion, Entry.Translate(Input%1000000000))
} else {
result = fmt.Sprintf("%s %s %s", Entry.Translate(Input/1000000000000), Entry.LocalizedEntity.Trillion, Entry.Translate(Input%1000000000000))
}
return strings.TrimSpace(result)
}

func (Entry EntryAr) ZeroResponse() string {
Expand Down
1 change: 1 addition & 0 deletions NumToWords/locales/Lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Lang struct {
Units []string
Teens []string
Tens []string
And string
Zero string
Hundred string
Thousand string
Expand Down
3 changes: 2 additions & 1 deletion NumToWords/locales/ar.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package locales

var AR = Lang{
Units: []string{"صفر", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Units: []string{"", "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة"},
Teens: []string{"عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر"},
Tens: []string{"", "", "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون"},
And: "و",
Zero: "صفر",
Hundred: "مئة",
Thousand: "الف",
Expand Down
1 change: 1 addition & 0 deletions NumToWords/locales/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var EN = Lang{
Units: []string{"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"},
Teens: []string{"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"},
Tens: []string{"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"},
And: "",
Zero: "zero",
Hundred: "hundred",
Thousand: "thousand",
Expand Down
4 changes: 2 additions & 2 deletions _example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

func main() {
input := 1000000000000
words, err := NumToWords.Convert(input, "en")
input := 32
words, err := NumToWords.Convert(input, "ar")
if err != nil {
return
}
Expand Down

0 comments on commit cc6fd9f

Please sign in to comment.