-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgt-cli.el
More file actions
81 lines (66 loc) · 2.53 KB
/
gt-cli.el
File metadata and controls
81 lines (66 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;;; gt-cli.el --- A command-line interface for gt -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Jen-Chieh Shen
;; Author: Jen-Chieh Shen <jcs090218@gmail.com>
;; Maintainer: Jen-Chieh Shen <jcs090218@gmail.com>
;; URL: https://github.com/emacs-eine/gt-cli
;; Version: 1.0.0
;; Package-Requires: ((emacs "28.1")
;; (gt "3.2.1")
;; (commander "0.7.0")
;; (msgu "0.1.0"))
;; Keywords: convenience
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; A command-line interface for Google Translate
;;
;;; Code:
(require 'gt)
(require 'msgu)
(defgroup gt-cli nil
"A command-line interface for gt."
:prefix "gt-cli-"
:group 'tool
:link '(url-link :tag "Repository" "https://github.com/emacs-eine/gt-cli"))
(defcustom gt-cli-source-language "auto"
"The default source language you wish to translate from."
:type 'string
:group 'gt-cli)
(defcustom gt-cli-target-language "ko"
"The default target language you wish to translate to."
:type 'string
:group 'gt-cli)
;; internal use
(defvar gt-cli--text nil)
;;;###autoload
(defun gt-cli (src-lang target-lang text)
"Translate text and output to standard output."
(when (string-empty-p text)
(error "The translation text cannot be an empty string"))
(let ((old-kill-ring kill-ring)
(gt-langs (or gt-langs
(list src-lang target-lang)))
(gt-default-translator (or gt-default-translator
(gt-translator :engines (gt-google-engine)
:render (gt-kill-ring-render)))))
(msgu-silent
(with-temp-buffer
(insert text)
(mark-whole-buffer)
(call-interactively #'gt-translate))
;; Pause until result came in.
(while (equal old-kill-ring kill-ring)
(sit-for 0.2)))
(princ (car kill-ring))))
(provide 'gt-cli)
;;; gt-cli.el ends here