Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtranslate #3

Open
gedw99 opened this issue Jun 26, 2023 · 1 comment
Open

gtranslate #3

gedw99 opened this issue Jun 26, 2023 · 1 comment

Comments

@gedw99
Copy link

gedw99 commented Jun 26, 2023

How about we add this as a service ?

This is rate limited but works well.

It does NOT do the work splitting like dragoman.

package main

import (
	"fmt"

	"github.com/bregydoc/gtranslate"
)

func main() {
	text := "Hello, {firstName}! This is a title."
	translated, err := gtranslate.TranslateWithParams(
		text,
		gtranslate.TranslationParams{
			From: "en",
			To:   "ja",
		},
	)
	if err != nil {
		panic(err)
	}

	fmt.Printf("en: %s | ja: %s \n", text, translated)
	
}

We could add it as a new service in the Services folder called "gtranslate"

Just need to wrap it and match the DeepL code pattern i guess.
Also need to add the word splitting.

import (
  "github.com/bounoable/deepl"
)

client := deepl.New("your-auth-key")

translated, sourceLang, err := client.Translate(
  context.TODO(),
  "Hello, world",
  deepl.Chinese,
)
if err != nil {
  log.Fatal(err)
}

log.Println(fmt.Sprintf("source language: %s", sourceLang))
log.Println(translated)
@bounoable
Copy link
Collaborator

So your idea is to add a new gtranslate service to access the Google Translate API for free? I like the idea, however I currently have no spare time to implement this. If you're interested, I would gladly merge a Pull Request that incorporates this feature.

Here's a basic guide to implementing it:

  1. Create a new gtranslate service in the /service/gtranslate directory.
  2. Implement the dragoman.Service interface similar to how deepl and the existing gcloud implementations are done.

You could start with something like this for the service.go file within the /service/gtranslate directory:

# /service/gtranslate/service.go
package gtranslate

import (
    "context"
    "github.com/bregydoc/gtranslate"
)

type Service struct{}

func (*Service) Translate(ctx context.Context, text, sourceLang, targetLang string) (string, error) {
    return gtranslate.TranslateWithParams(...)
}
  1. Finally, remember to add a new --gtranslate flag to the cli package to allow users to choose gtranslate as an option.

Please feel free to reach out if you need any assistance or further clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants