translate: add snippet for "model" option (beta)
@@ -99,3 +99,26 @@ func listSupportedLanguages(w io.Writer, targetLanguage string) error {
return nil
}
+
+func translateTextWithModel(targetLanguage, text, model string) (string, error) {
+ ctx := context.Background()
+
+ lang, err := language.Parse(targetLanguage)
+ if err != nil {
+ return "", err
+ }
+
+ client, err := translate.NewClient(ctx)
+ if err != nil {
+ return "", err
+ }
+ defer client.Close()
+
+ resp, err := client.Translate(ctx, []string{text}, lang, &translate.Options{
+ Model: model, // Either "mnt" or "base".
+ })
+ if err != nil {
+ return "", err
+ }
+ return resp[0].Text, nil
+}
