Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Make Translate & GetSuggestions functions public
Browse files Browse the repository at this point in the history
  • Loading branch information
mesuutt committed May 13, 2017
1 parent 99e29ff commit 6a95380
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (trans *Translation) WordTypeShortDisplay() string {

var userAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0"

// Make request to tureng.com and return scraped document
// Make request to tureng.com and return grabbed document
func (tureng *Tureng) getDocument(text string) (*goquery.Document, error) {

url := fmt.Sprintf("http://www.tureng.com/en/turkish-english/%s", text)
Expand All @@ -81,7 +81,8 @@ func (tureng *Tureng) getDocument(text string) (*goquery.Document, error) {
return goquery.NewDocumentFromResponse(res)
}

func (tureng *Tureng) translate(text string) (result Content, err error) {
// Translate given text
func (tureng *Tureng) Translate(text string) (result Content, err error) {

doc, err := tureng.getDocument(text)
tureng.Document = doc
Expand Down Expand Up @@ -155,7 +156,7 @@ func (tureng *Tureng) translate(text string) (result Content, err error) {
return
}

func (tureng *Tureng) getSuggestions() []string {
func (tureng *Tureng) GetSuggestions() []string {
suggestions := []string{}
tureng.Document.Find(".suggestion-list a").Each(func(i int, s *goquery.Selection) {
suggestions = append(suggestions, s.Text())
Expand Down Expand Up @@ -207,15 +208,15 @@ func main() {

tureng := &Tureng{Config: *conf}
text := strings.Join(flag.Args(), " ")
result, err := tureng.translate(text)
result, err := tureng.Translate(text)

if err != nil {
log.Fatal(err)
}

if result.ResultCount == 0 {
fmt.Printf("There is no translation found for '%s' \n", text)
suggs := tureng.getSuggestions()
suggs := tureng.GetSuggestions()

if len(suggs) > 0 {
fmt.Printf("\n==== Suggestions ====\n")
Expand Down

0 comments on commit 6a95380

Please sign in to comment.