Coder Social home page Coder Social logo

google-translate's Introduction

Emacs interface to Google Translate

Join the chat at https://gitter.im/atykhonov/google-translate MELPA MELPA Stable

Summary

This package allows to translate the strings using Google Translate service directly from GNU Emacs.

Installation

From MELPA

Just run M-x package-install RET google-translate RET

Manual installation

Assuming that the file google-translate.el is somewhere on the load path, add the following lines to your .emacs file:

(require 'google-translate)
(require 'google-translate-default-ui)
(global-set-key "\C-ct" 'google-translate-at-point)
(global-set-key "\C-cT" 'google-translate-query-translate)

or

(require 'google-translate)
(require 'google-translate-smooth-ui)
(global-set-key "\C-ct" 'google-translate-smooth-translate)

The difference between these configurations is in UI which will be used: Default UI or Smooth UI.

Default UI (google-translate-default-ui.el)

This file provides default UI for the Google Translate package. It was originally written by Oleksandr Manzyuk and was part of google-translate.el. It was extracted to google-translate-default-ui.el file due to refactoring (the goal of which is to separate backend from UI and provide better way for having different UIs for Google Translate package).

Invoking the function google-translate-query-translate queries the source and target languages and text to translate, and shows a buffer with available translations of the text. Invoking the function google-translate-at-point translates the word at point or the active region.

Default UI Customization

You can customize the following variables:

  • google-translate-default-source-language

  • google-translate-default-target-language

If the variable google-translate-default-source-language is set to a non-NIL value, the source language won't be queried and that value will be used instead. Analogously, if you set the variable google-translate-default-target-language to some non-NIL value, that value will be used without querying.

You can always override this behavior by supplying a C-u prefix argument to the function google-translate-query-translate.

Here is an example. Suppose that your native language is Russian and you frequently need to translate from various languages to Russian. Then it is reasonable

  • to set the variable google-translate-default-target-language to "ru", and

  • to leave google-translate-default-source-language set to its default value, NIL.

In this case, the function google-translate-query-translate is only going to query the source language and text to translate. If you need to translate to some language other than Russian, you can override the default for the target language by supplying a C-u prefix argument, in which case you will be queried for both the source and target languages, as well as text to translate.

If you frequently translate from some fixed language, it is also reasonable to set google-translate-default-source-language to an appropriate value.

If you have both the default source and target languages specified, you may like to bind functions google-translate-at-point-reverse and google-translate-query-translate-reverse to some keys, e.g.:

(global-set-key (kbd "C-c r") 'google-translate-at-point-reverse) (global-set-key (kbd "C-c R") 'google-translate-query-translate-reverse)

This will allow you to quickly translate in the reverse direction. When the default source (resp. target) language is not set, the target (resp. source) language of the reverse translation will be queried interactively.

The admitted values of google-translate-default-source-language and google-translate-default-target-language are the codes of the languages supported by Google Translate (like "ru" for Russian above). See google-translate-supported-languages for the list of the supported languages, or customize the defaults using the customization mechanism of Emacs. Setting a default language to NIL means that language will always be queried. Moreover, the variable google-translate-default-source-language can be set to a special value "auto" that is interpreted as the instruction for Google Translate to detect the source language. This option is also available when you are queried for the source language: simply leave this parameter blank by pressing RET. (If you have enabled the ido-style completion, "Detect language" is going to be the first option, which you can select simply by hitting RET.)

Smooth UI (google-translate-smooth-ui.el)

Smooth UI is a just alternative to the Default UI. It was written with mind to provide improved user interface and, especially, to achieve better supporting of many default languages. Default UI supports two default languages very well but there is no space for the third one.

Invoking the function google-translate-smooth-translate queries text and (optionally) the source and target languages to translate, and shows a buffer with available translations of the text.

Smooth UI Configuration:

It is reasonable to define the following variable:

  • google-translate-translation-directions-alist

  • google-translate-preferable-input-methods-alist

google-translate-translation-directions-alist alist is intended to contain translation directions.

For example it could be defined (in your .emacs or init.el) as:

(setq google-translate-translation-directions-alist '(("en" . "ru")))

in this way one translation direction ("en" > "ru") is defined and when google-translate-smooth-translate function executes it will output the prompt (in minibuffer) which will looks like as the following:

[English > Russian] Translate:

You may set as many translation directions as you would like to. For example such piece of code will define four translation directions:

(setq google-translate-translation-directions-alist
      '(("de" . "en") ("en" . "de") ("de" . "fr") ("fr" . "de")))

in this way, when google-translate-smooth-translate function executes you'll be queried by the prompt which will looks like the following:

[German > English] Translate:

and, also in this way, you'll be able to switch between different translation directions directly from minibuffer by using C-n and C-p key bindings. C-n key binding changes current translation direction to the next direction defined in the google-translate-translation-directions-alist variable. And C-p key binding changes current translation direction to the previous one. Thus, while executing google-translate-smooth-translate function and having in minibuffer such prompt:

[German > English] Translate:

then after pressing C-n you'll get the following prompt:

[English > German] Translate:

By default google-translate-translation-directions-alist is empty and thus during execution of google-translate-smooth-translate you'll be queried (to input a text) by the prompt:

Translate:

And after inputed text you'll be queried also for the source and target languages. To let the package to be known which languages you would like to always use and to avoid repetitive language quering it is reasonable to define them in the mentioned google-translate-translation-directions-alist variable.

Common UI Customization

Described customization options are actual for both UI features: Default UI and Smooth UI.

You can customize the following variables:

  • google-translate-output-destination

  • google-translate-enable-ido-completion

  • google-translate-show-phonetic

  • google-translate-listen-program

  • google-translate-pop-up-buffer-set-focus

google-translate-output-destination determines translation output destination. If nil the translation output will be displayed in the pop up buffer. If value equal to echo-area then translation outputs in the Echo Area (see Echo Area). In case of popup the translation outputs to the popup tooltip using popup package. In case of kill-ring the translation outputs to the kill ring. And in case of current-buffer the translation outputs to the current buffer. If you would like output translation to the Echo Area you would probably like to increase it because only part of translation could be visible there with the default settings. To increase Echo Area you could increase the value of max-mini-window-height variable, for example: (setq max-mini-window-height 0.5).

If google-translate-enable-ido-completion is non-NIL, the input will be read with ido-style completion.

The variable google-translate-show-phonetic controls whether the phonetic spelling of the original text and its translation is displayed if available. If you want to see the phonetics, set this variable to t.

The variable google-translate-listen-program determines the program to use to listen translations. By default the program looks for mplayer in the PATH, if mplayer is found then listening function will be available and you'll see Listen button in the buffer with the translation. You can use any other suitable program. If you use Windows please download and unpack mplayer and add its path (directory) to to the system PATH variable. Please note that translation listening is not available if google-translate-output-destination is set to echo-area or pop-up.

The variable google-translate-pop-up-buffer-set-focus determines whether window (buffer) with translation gets focus when it pop ups. If nil, it doesn't get focus and focus remains in the same window as was before translation. If t, window (buffer with translation) gets focus. Please note that that setting works only for pop up buffer, i.e. when google-translate-output-destination is nil.

The google-translate-input-method-auto-toggling variable determines whether input method auto toggling is enabled or not.

While switching among languages I noticed that I change input method quite often. Input method auto toggling allows switch on appropriate input method while switching among languages. Auto toggling will work in case of google-translate-input-method-auto-toggling is set to t and google-translate-preferable-input-methods-alist is defined properly.

This variable may be defined as follow (just for example):

(setq google-translate-preferable-input-methods-alist '((nil . ("en"))
                                                        (ukrainian-programmer-dvorak . ("ru" "uk"))))

In this way, input method is disabled (because of nil) for the minibuffer when source language is English. And "ukrainian-programmer-dvorak" input method is enabled when source language is Russian or Ukrainian.

Customization of faces

  • google-translate-text-face, used to display the original text (defaults to default)

  • google-translate-phonetic-face, used to display the phonetics (defaults to shadow)

  • google-translate-translation-face, used to display the highest ranking translation (defaults to default with the weight attribute set to bold)

  • google-translate-suggestion-label-face used to display the label for suggestion (defaults to default with the foreground attribute set to red)

  • google-translate-suggestion-face used to display the suggestion in case of word is misspelled (defaults to default with the slant attribute set to italic and underline attribute set to t)

  • google-translate-listen-button-face used to display the "Listen" button (defaults to `height' 0.8).

For example, to show the translation in a larger font change the height attribute of the face google-translate-translation-face like so:

  (set-face-attribute 'google-translate-translation-face nil :height 1.4)

Utilize curl, wget or else as a last resort

If you have any troubles that relate to http, like Search failed: ",tkk:'", try to use curl or wget for the backend method.

The variable 'google-translate-backend-method switches the backend method and currently available symbols are below:

  • emacs: use built in url-retrieve-synchronously (default)
  • curl: invoke curl
  • wget: invoke wget

So if you prefer curl, put following line to your init.el:

(setq google-translate-backend-method 'curl)

In case neither curl nor wget is your preference, you can add another command to the variable 'google-translate-backend-commands and employ it, for example:

(push '(foo :name "foo-x86" :args ("-q" "--agent"))
      google-translate-backend-commands)
(setq google-translate-backend-method 'foo)

For further information, please refer to the documentation of 'google-translate-backend-commands.

Additionally, these variables would be useful for troubleshooting:

  • google-translate-backend-user-agent, user agent string for HTTP request header (defaults to "Emacs")

  • google-translate-backend-debug, log URL access activities to the buffer *google-translate-backend-debug* (defaults to nil)

Contributors

google-translate's People

Contributors

alezost avatar atykhonov avatar calancha avatar dalanicolai avatar gitter-badger avatar in3d avatar jcs090218 avatar jumper047 avatar kdmsnr avatar leuven65 avatar lorniu avatar mankoff avatar manzyuk avatar marioba avatar momomo5717 avatar mugijiru avatar ogawahirofumi avatar shigemk2 avatar stardiviner avatar superbear avatar syohex avatar t-suwa avatar takumikinjo avatar tsdh avatar visortelle avatar xuchunyang avatar zonuexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-translate's Issues

Google translate audio output

Dear atykhonov,

Thanks for helping me to solve the issue about read phonetically of google translate in the issue manzyuk/google-translate#13. By adding the (setq google-translate-show-phonetic t), the function was ideally accomplished.

I am looking forwarding you to accomplish the audio output of google translate in emacs. If it can be realized, I will be really very appreciated!!

Best regards!

Is it possible to write text by voice dictation?

Hello,

I haven't yet tried your module. For the name, I don't think it is possible nor the objective of this project. I was wondering if it is possible to do dictations to emacs similarly to dragon naturally speaking using the google api so the text gets written automatically in emacs?

If not, are you aware of any project for emacs that is able to achieve this?

Thanks.

Support long text for translate_tts

If text length is longer than 200 (in my test, limit was 200),
translate_tts returns 404 error.

To support longer than 200, this tries to split text at sentence if
possible. Then pass made URLs to google-translate-listen-program as
arguments at once.

Like following,

program "http://...&total=2&idx=0..." "http://...&total=2&idx=1..."

With this, the program can process long text.

patch file

google-translate-backend--emacs: Search failed

Hi,

I've been using this package for a while and I remember it was working.
However, I'm getting the following error now (copied from *Messages*):

Contacting host: translate.google.com:80
google-translate-backend--emacs: Search failed: "

"

In *google-translate-backend-debug* I get:

Sun Aug 25 11:08:37 2019
("http://translate.google.com/" emacs)
-- begin --

-- end --

Do you have any ideas on this error?

Versions:
Ubuntu 19.04
Emacs 26.1

[Feature request] Listen to translation in target language

First off, thank you for creating this very useful package :-)

I like the ability to listen to the correct pronunciation a lot. I was a bit surprised to find that there is a listen button only for the source language. To listen to the pronunciation in the target language, which is very useful when translating into a foreign language, I now have to copy the translation, reverse the direction of the translation, translate again, then activate the listen button, which is a bit cumbersome.

Please consider adding a button to listen to the translation in target language also.

Automatic listening

Hi @atykhonov,

Can you see automatic listening will be a good feature for google-translate? In my situation, when i start to read the article, I will call the command to get the listening with mouse or locate the button by keyboard. Surely it will save much time if you can give a option to make it automatically.

Best regards.
llcc

[Feature request] Ability to change source text in *Google Translate* buffer

Hello,

Just in case that wouldn't be too difficult, I think it'd be nice to have an editable buffer where you can change the source language text and get that new text be translated via a button or a refresh command.

A similar idea would be to be able to change, in that buffer, the language pair with C-n/C-p.

WDYT?

Try uncomment-region before translate

For example, if I try to translate emacs-lisp-mode like following,

[region-start]
;; If `google-translate-enable-ido-completion' is non-NIL, the input
;; will be read with ido-style completion.
[region-end]

comment mark bother to translate it, ";;" works like the punctuation.

So this copies the region, uncommented, then make string without
modifying original buffer. The result like following

[region-start]
If `google-translate-enable-ido-completion' is non-NIL, the input
will be read with ido-style completion.
[region-end]

patch file

Phonetic translation

Hi,

First of all, thanks for the great work. Very useful package. I found a little issue with phonetic translation though. At least on my system the json received from google has the phonetic translation in position 3, not 2, and it seems even if there is a phonetic translation, it is never shown in the result buffer.

I fixed the problem for myself by modifying the functions google-translate-json-translation-phonetic and google-translate-translate but I am not really confident my change in the later makes sense...

(defun google-translate-json-translation-phonetic (json)
  "Retrieve from the JSON (which returns by the
`google-translate-request' function) phonetic transcription of
the translating text."
  (mapconcat #'(lambda (item) (aref item 3))
             (aref json 0) ""))
(defun google-translate-translate (source-language target-language text)
...
          (when detailed-translation
            (google-translate--buffer-output-text-phonetic text-phonetic))
          (google-translate--buffer-output-translation translation)
          (when translation-phonetic
            (google-translate--buffer-output-translation-phonetic translation-phonetic))
          (if detailed-translation
              (google-translate--buffer-output-detailed-translation
               detailed-translation
               translation)
...

JSON readtable error

Hi Andrey,
I am getting a "JSON readtble error" when I try to use google-translate with a block of text larger than about 1080 characters. Otherwise it works fine.

My .emacs file contains the following:

(require 'google-translate)
(require 'google-translate-smooth-ui)
(global-set-key "\C-ct" 'google-translate-smooth-translate)
(setq google-translate-translation-directions-alist '(("is" . "en")))

Any ideas why this is happening?
Many thanks,

Julian

Can't find any hooks

I'd like to use a hook to focus on the translate window when it shows. I see you're using help-mode, and I have help-window-select set to t already. I could make a function, of course, but, if there is a hook I'd rather use it.

Google is returning Error 403 (Forbidden)

Hello,

Suddenly evaluating (google-translate--request "en" "uk" "hello") returns the error below. I tried from two different hosts. The page says,

403. That’s an error. Your client does not have permission to get URL /translate_a/single?client=t&ie=UTF-8&oe=UTF-8&sl=en&tl=uk&q=hello&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&pc=1&otf=1&srcrom=1&ssel=0&tsel=0&tk=160396%7C290233 from this server. That’s all we know.

HTML source:
`

<title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style>

403. That’s an error.

Your client does not have permission to get URL /translate_a/single?client=t&ie=UTF-8&oe=UTF-8&sl=en&tl=uk&q=hello&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&pc=1&otf=1&srcrom=1&ssel=0&tsel=0&tk=160396%7C290233 from this server. That’s all we know.`

Failed to search TTK

I was using google-translate for months and suddenly I started getting this error for every translation.
I don't recall changing anything so I don't understand why it stopped working.

I am using version 0.11.14 on Emacs 25.2.2

Thank you!

Allow output to more than 1 place

Currently, I want my output to kill-ring, so I have the current line:
(setq google-translate-output-destination 'kill-ring)

But I want it to output to both kill-ring and echo-area. I tried the following:
(setq google-translate-output-destination (quote (kill-ring echo-area)))
but it doesn't work.

Could you please show me how to make this work?

the google-translate.el error

I want to add google-translate.el in this config from MELPA, some message show that the init config can't work:

Warning (initialization): An error occurred while loading /Users/sb/.emacs.d/init.el': End of file during parsing: /Users/sb/.emacs.d/lisp/init-google-translate.el To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the--debug-init' option to view a complete error backtrace.

the content of init-google-translate.el is:
;; google-translate packages
(require-package 'google-translate)
(require-package 'google-translate-smooth-ui)
;; shotcut
(global-set-key "\C-ct" 'google-translate-smooth-translate)
;; translate en <-> cn
(setq google-translate-translation-directions-alist '(("en" . "cn") ("cn" . "en"))
(provide 'init-google-translate)

init.el:
(require 'init-google-translate)
what happened?

Disable text at point when calling google-translate-smooth-translate

I'm binding C-c t to google-translate-smooth-translate function. Whenever I press the key, the prompt shows up with a text at the current cursor or selected text. Is there anyway to turn off this feature so that when I press the key, no text will show up and it allows me to input my own text?

Translating of a short word gives an error

(google-translate-translate "Swedish" "English" "i")
It gives an error, even tho such short words are
common in many languages and are likely to be
translated now and then.
  • reported by Emanuel Berg in the Emacs mailing list.

caching the results

Hi, Andrii!

I have some vocabulary I translate quite often, so I thoght it would be quite handy to have basic caching implemented, because each translation may take up to a few bitter seconds and that's painful. What do you think about it?

Feature: A -> B -> A closure translation

Use case is : I obviously speak a french-glish and I expect the Google Translate engine is aware of common English language patterns. Thus to sanitize my incorrect English, I perform a closure translation English -> French -> English and I incrementally try to find something that look fine in both languages.

Not sure it is useful for all pair of languages, but it can be helpful for the closest one.

Have the translated output in the kill-ring

Hello, when trying to automate (with an Emacs macro) the translation of terms in a column, I found it'd be good if GT would:

  • unselect the selected region
  • put the translation in the kill-ring (so that we simply have to press C-y to insert it somewhere)

Thanks!

Failed to search TKK

Any translation attempt is failing with the error:
google-translate--search-tkk: Failed to search TKK

Wrong type argument

With GNU Emacs 25.1.50.1 (armv7l-unknown-linux-gnueabihf, X toolkit, Xaw3d scroll bars) of 2015-12-26, I get:
Wrong type argument: integer-or-marker-p, 4294967295.0

Here is the backtrace. I hope this helps, Frank

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p 4294967295.0)
logand(413504475 4294967295.0)
google-translate--gen-rl(403419 "+-a^+6")
#[(a e) "\303� \n"\207" [a e vb google-translate--gen-rl] 3](403318 101)
cl-reduce(#[(a e) "\303� \n"\207" [a e vb google-translate--gen-rl] 3] "enter" :initial-value 403318)
google-translate--gen-tk("enter")
google-translate--request("en" "de" "enter")
google-translate-request("en" "de" "enter")
google-translate-translate("en" "de" "enter")
%google-translate-at-point(nil nil)
google-translate-at-point(nil)
funcall-interactively(google-translate-at-point nil)
call-interactively(google-translate-at-point record nil)
command-execute(google-translate-at-point record)
execute-extended-command(nil "google-translate-at-point" nil)
funcall-interactively(execute-extended-command nil "google-translate-at-point" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)

Support pronunciation/transliteration

Google Translate does some of this. Not sure how much the API supports, if anything.

Specifically, it would be awesome if google-translate displayed pinyin pronunciation/transliteration for Chinese translations.

Support long text for translate_tts

If text length is longer than 200 (in my test, limit was 200),
translate_tts returns 404 error.

To support longer than 200, this tries to split text at sentence if
possible. Then pass made URLs to google-translate-listen-program as
arguments at once.

Like following,

program "http://...&total=2&idx=0..." "http://...&total=2&idx=1..."

With this, the program can process long text.
patch file

Error during translation "wrong-type-argument char-or-string-p nil"

I've installed the current version google-translate from git. I added these lines to my .emacs:

(add-to-list 'load-path "~/emacs/google-translate")
(require 'google-translate)
(require 'google-translate-smooth-ui)
(global-set-key "\C-ct" 'google-translate-smooth-translate)
(setq debug-on-error t)

When I selected the english word and then try to translate it from english to Russian I've got an error.

Debugger entered--Lisp error: (wrong-type-argument char-or-string-p nil)
  insert("Translate from English to Russian:\n" #("\nAfghanistan\n" 0 13 (face google-translate-text-face)) nil "" #("\nАфганистан\n" 0 12 (face google-translate-translation-face)) "" "\nnoun\n 1. Афганистан\n")
  (let ((translation (progn (or (and (vectorp gtos) (>= (length gtos) 10) (memq (aref gtos 0) cl-struct-gtos-tags)) (error "%s accessing a non-%s" (quote gtos-translation) (quote gtos))) (aref gtos 6))) (detailed-translation (progn (or (and (vectorp gtos) (>= (length gtos) 10) (memq (aref gtos 0) cl-struct-gtos-tags)) (error "%s accessing a non-%s" (quote gtos-detailed-translation) (quote gtos))) (aref gtos 8)))) (insert (google-translate--translation-title gtos "Translate from %s to %s:\n") (google-translate--translating-text gtos (if (null google-translate-listen-program) "\n%s\n" "\n%s")) (if google-translate-listen-program (progn (google-translate--listen-button gtos))) (google-translate--text-phonetic gtos "\n%s\n") (google-translate--translated-text gtos "\n%s\n") (google-translate--translation-phonetic gtos "\n%s\n") (if detailed-translation (google-translate--detailed-translation detailed-translation translation "\n%s\n" "%2d. %s\n") (google-translate--suggestion gtos))))
  google-translate-buffer-insert-translation([cl-struct-gtos "en" "ru" "Afghanistan" "en" "" "Афганистан" "Afganistan" [["noun" ["Афганистан"] [["Афганистан" ["Afghanistan"] nil 0.40403652]] "Afghanistan" 1]] nil])
  (progn (set-buffer buffer-name) (google-translate-buffer-insert-translation gtos))
  (prog1 (progn (set-buffer buffer-name) (google-translate-buffer-insert-translation gtos)) (internal-temp-output-buffer-show buf))
  (let* ((old-dir default-directory) (buf (save-current-buffer (set-buffer (get-buffer-create buffer-name)) (prog1 (current-buffer) (kill-all-local-variables) (setq default-directory old-dir) (setq buffer-read-only nil) (setq buffer-file-name nil) (setq buffer-undo-list t) (let ((inhibit-read-only t) (inhibit-modification-hooks t)) (erase-buffer) (run-hooks (quote temp-buffer-setup-hook)))))) (standard-output buf)) (prog1 (progn (set-buffer buffer-name) (google-translate-buffer-insert-translation gtos)) (internal-temp-output-buffer-show buf)))
  (let ((buffer-name "*Google Translate*")) (let* ((old-dir default-directory) (buf (save-current-buffer (set-buffer (get-buffer-create buffer-name)) (prog1 (current-buffer) (kill-all-local-variables) (setq default-directory old-dir) (setq buffer-read-only nil) (setq buffer-file-name nil) (setq buffer-undo-list t) (let (... ...) (erase-buffer) (run-hooks ...))))) (standard-output buf)) (prog1 (progn (set-buffer buffer-name) (google-translate-buffer-insert-translation gtos)) (internal-temp-output-buffer-show buf))))
  google-translate-buffer-output-translation([cl-struct-gtos "en" "ru" "Afghanistan" "en" "" "Афганистан" "Afganistan" [["noun" ["Афганистан"] [["Афганистан" ["Afghanistan"] nil 0.40403652]] "Afghanistan" 1]] nil])
  (cond ((null google-translate-output-destination) (google-translate-buffer-output-translation gtos)) ((equal google-translate-output-destination (quote echo-area)) (google-translate-echo-area-output-translation gtos)) ((equal google-translate-output-destination (quote popup)) (google-translate-popup-output-translation gtos)))
  (let* ((detailed-translation (google-translate-json-detailed-translation json)) (gtos (make-gtos :source-language source-language :target-language target-language :auto-detected-language (aref json 2) :text text :text-phonetic (google-translate-json-text-phonetic json) :translation (google-translate-json-translation json) :translation-phonetic (google-translate-json-translation-phonetic json) :detailed-translation detailed-translation :suggestion (if (null detailed-translation) (progn (google-translate-json-suggestion json)))))) (cond ((null google-translate-output-destination) (google-translate-buffer-output-translation gtos)) ((equal google-translate-output-destination (quote echo-area)) (google-translate-echo-area-output-translation gtos)) ((equal google-translate-output-destination (quote popup)) (google-translate-popup-output-translation gtos))))
  (if (null json) (message "Nothing to translate.") (let* ((detailed-translation (google-translate-json-detailed-translation json)) (gtos (make-gtos :source-language source-language :target-language target-language :auto-detected-language (aref json 2) :text text :text-phonetic (google-translate-json-text-phonetic json) :translation (google-translate-json-translation json) :translation-phonetic (google-translate-json-translation-phonetic json) :detailed-translation detailed-translation :suggestion (if (null detailed-translation) (progn (google-translate-json-suggestion json)))))) (cond ((null google-translate-output-destination) (google-translate-buffer-output-translation gtos)) ((equal google-translate-output-destination (quote echo-area)) (google-translate-echo-area-output-translation gtos)) ((equal google-translate-output-destination (quote popup)) (google-translate-popup-output-translation gtos)))))
  (let* ((json (google-translate-request source-language target-language text))) (if (null json) (message "Nothing to translate.") (let* ((detailed-translation (google-translate-json-detailed-translation json)) (gtos (make-gtos :source-language source-language :target-language target-language :auto-detected-language (aref json 2) :text text :text-phonetic (google-translate-json-text-phonetic json) :translation (google-translate-json-translation json) :translation-phonetic (google-translate-json-translation-phonetic json) :detailed-translation detailed-translation :suggestion (if (null detailed-translation) (progn ...))))) (cond ((null google-translate-output-destination) (google-translate-buffer-output-translation gtos)) ((equal google-translate-output-destination (quote echo-area)) (google-translate-echo-area-output-translation gtos)) ((equal google-translate-output-destination (quote popup)) (google-translate-popup-output-translation gtos))))))
  google-translate-translate("en" "ru" "Afghanistan")
  (let* ((text (google-translate-query-translate-using-directions)) (source-language (google-translate--current-direction-source-language)) (target-language (google-translate--current-direction-target-language))) (if (null source-language) (progn (setq source-language (google-translate-read-source-language)))) (if (null target-language) (progn (setq target-language (google-translate-read-target-language)))) (google-translate-translate source-language target-language text))
  google-translate-smooth-translate()
  call-interactively(google-translate-smooth-translate nil nil)

When I try to use default default interface I've got the same error.

GNU Emacs 24.3.1
MacOSX 10.9.4

how to make google-translate work in an erc buffer ?

hi,
GT works well here in a lisp buffer, in the scratch buffer, in any org buffer, but won't in an erc buffer. Messages buffer says : "Contacting host: translate.google.com:80 facemenu-add-face: Text is read-only", GT buffer gets cleared. Any help ?

Strip translating string

When perform google-translate-smooth-translate with several selected lines in the minibuffer appears broken string.

[Feature request] Add Input method auto toggling to Default UI

Hi!

What do you think about adding auto toggling feature in the Default UI like in Smooth UI?
I sticking to the Default UI, because I am able to use 4 separate keybindings for:

  • google-translate-query-translate-reverse
  • google-translate-query-translate
  • google-translate-at-point-reverse
  • google-translate-at-point

Feature request: close the opened window when the cursor moves.

Hello, the extension is pretty good to use. Really appreciate your work.

Usually I don't need to show the newly opened window anymore after I know the meaning. So I want it to be automatically closed after I move the cursor. However, when I call "other-window" command, the dict window should get focus instead of being closed.

I wonder if the author can add this feature and a new option to switch it?
If not, can you help me how to write code to implement it by myself? I am new to Emacs Lisp.

Thanks!

[Question] - Raw string API.

Hi, thanks for this amazing package!

I just wonder is there a function that I could call and just return the translated text as a string? If not, do you this is possible to do from this package? What I would image would be something like.

(defun google-translate--get-translated (src-lan target-lan text/sentence)
  // code here..
  )

Thanks.

how to use in pdf-tools?

the pdf text content doesn't like any content in emacs file
you may format it that emacs can read it and then translate it
how to pass the format pdf content to this google-translate function?

json readtable error

Hi, I can't translate region in buffer, do you know what's going on?

in Message
Contacting host: translate.google.com:80
json-read: JSON readtable error

Link suggestion

Make suggested word as a link. So user will be able to hit Enter / click and get translation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.