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

Fix TKK error. #81

Merged
merged 3 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bump-version.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"google-translate-pkg.el"
"google-translate-smooth-ui.el"
"Makefile"))
(:current-version "0.11.14"))
(:current-version "0.11.15"))
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ELC = $(SRC:.el=.elc)
CASK ?= cask
PKG_DIR := $(shell $(CASK) package-directory)
FEATURES = $(wildcard features/*.feature)
VERSION = 0.11.14
VERSION = 0.11.15
TARGET_DIR = google-translate-$(VERSION)

all: test marmalade tag
Expand Down
4 changes: 2 additions & 2 deletions features/google-translate-default-ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ Feature: Default UI for Google Translate
Scenario: Suggestion when word is misspelled
Given I set google-translate-default-source-language to "en"
Given I set google-translate-default-target-language to "ru"
When I translate "sudgest"
When I translate "sugest"
Then I should see suggestion "suggest"

Scenario: Linked suggestion: click on suggestion
Given I set google-translate-default-source-language to "en"
Given I set google-translate-default-target-language to "ru"
When I translate "sudgest"
When I translate "sugest"
Then I should see suggestion "suggest"
And I press "TAB"
And I press "TAB"
Expand Down
4 changes: 2 additions & 2 deletions features/google-translate-smooth-ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ Feature: Smooth UI for Google Translate

Scenario: Suggestion when word is misspelled
Given I set google-translate-translation-directions-alist to (("en" . "ru"))
When I translate "sudgest"
When I translate "sugest"
Then I should see suggestion "suggest"

Scenario: Linked suggestion: click on suggestion
Given I set google-translate-translation-directions-alist to (("en" . "ru"))
When I translate "sudgest"
When I translate "sugest"
Then I should see suggestion "suggest"
And I press "TAB"
And I press "TAB"
Expand Down
2 changes: 1 addition & 1 deletion google-translate-core-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down
4 changes: 2 additions & 2 deletions google-translate-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down Expand Up @@ -261,7 +261,7 @@ translation it is possible to get suggestion."

(defun google-translate-version ()
(interactive)
(message "Google Translate (version): %s" "0.11.14"))
(message "Google Translate (version): %s" "0.11.15"))


(provide 'google-translate-core)
Expand Down
2 changes: 1 addition & 1 deletion google-translate-default-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down
2 changes: 1 addition & 1 deletion google-translate-pkg.el
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(define-package "google-translate" "0.11.14"
(define-package "google-translate" "0.11.15"
"Emacs interface to Google Translate.")
2 changes: 1 addition & 1 deletion google-translate-smooth-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down
41 changes: 15 additions & 26 deletions google-translate-tk.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down Expand Up @@ -46,13 +46,6 @@
(defvar google-translate--tkk-url
"http://translate.google.com/")

(defvar google-translate--tkk-regex
"TKK=eval('((function(){var\\s-+a\\\\x3d\\(-?[0-9]+\\);var\\s-+b\\\\x3d\\(-?[0-9]+\\);return\\s-+\\([0-9]+\\)"
"Regexp for `google-translate--search-tkk'.")

(defvar google-translate--tkk-debug
nil
"For debugging of tk related issues.")

(defun google-translate--bit-v-2comp (v)
"Return the two's complement of V."
Expand Down Expand Up @@ -128,28 +121,23 @@ D is an integer."

(defun google-translate--search-tkk ()
"Search TKK."
(if (re-search-forward google-translate--tkk-regex nil t)
(mapcar #'string-to-number
(list (match-string 1) (match-string 2) (match-string 3)))
(error "Failed to search TKK")))
(let ((start nil)
(tkk nil)
(nums '()))
(setq start (search-forward ";TKK='"))
(search-forward "';")
(backward-char 2)
(setq tkk (buffer-substring start (point)))
(setq nums (split-string tkk "\\."))
(list (string-to-number (car nums))
(string-to-number (car (cdr nums))))))

(defun google-translate--get-b-d1 ()
"Return a list of b and d1 for `google-translate--gen-tk'."
(let* ((url-request-extra-headers '(("Connection" . "close")))
(buf (url-retrieve-synchronously google-translate--tkk-url))
(debug-buffer-name "*Google Translate Debug*")
tkk-contents
tkk-ls)
(buf (url-retrieve-synchronously google-translate--tkk-url)))
(with-current-buffer buf
(setq tkk-ls (google-translate--search-tkk))
(setq tkk-contents (buffer-string)))
(when google-translate--tkk-debug
(with-output-to-temp-buffer debug-buffer-name
(prin1 tkk-contents))
(select-window (display-buffer debug-buffer-name)))
(when (buffer-live-p buf) (kill-buffer buf))
(list (cl-third tkk-ls)
(google-translate--lsh (+ (cl-first tkk-ls) (cl-second tkk-ls)) 0))))
(google-translate--search-tkk))))

(defun google-translate--gen-rl (a b)
(cl-loop for c from 0 below (- (length b) 2) by 3
Expand Down Expand Up @@ -178,7 +166,8 @@ D is an integer."
(setq a (ffloor (mod a 1e6)))
(format "%s.%s"
(car (split-string (number-to-string a) "\\."))
(car (split-string (number-to-string (google-translate--logxor a b)) "\\.")))))
(car (split-string (number-to-string
(google-translate--logxor a b)) "\\.")))))


(provide 'google-translate-tk)
Expand Down
2 changes: 1 addition & 1 deletion google-translate.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Oleksandr Manzyuk <[email protected]>
;; Maintainer: Andrey Tykhonov <[email protected]>
;; URL: https://github.com/atykhonov/google-translate
;; Version: 0.11.14
;; Version: 0.11.15
;; Keywords: convenience

;; Contributors:
Expand Down