TTTrans 0.2.1 → 24.03.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +37 -12
- data/README.md +22 -13
- data/exe/ttt +34 -10
- data/lib/tttrans/version.rb +1 -1
- data/lib/tttrans.rb +40 -16
- data/tttrans.gemspec +3 -12
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfc529c1f1edbc1c44d5cf405126da41a83f860c95042a7a7f77850f57a09d6
|
4
|
+
data.tar.gz: 5a51bd707ef25939a93d5d0b6cfd9aeff9be1317f6ee21499f930cfc1dafaf2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a2a2ab5c3a2a039d2334df4392cec1e28b2b54cd5c789c76fc85e6ec10d7dc23f0b36d2e5eef7e656bbb7179a3efb8c318b62c44b7b7257e9c1ecd7485db32f
|
7
|
+
data.tar.gz: 94884826d46fd311343662abc40177f18b812babaf7196123fe67490f68ae86ba400518966de0921fcbbc490ddc4c0527bc6020ca731ea461afc6671c8f2c62a
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,43 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
tttrans (24.03.31)
|
5
5
|
inifile (~> 3.0.0)
|
6
|
-
|
6
|
+
oauth2 (~> 2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
|
+
base64 (0.2.0)
|
13
|
+
faraday (2.9.0)
|
14
|
+
faraday-net_http (>= 2.0, < 3.2)
|
15
|
+
faraday-net_http (3.1.0)
|
16
|
+
net-http
|
17
|
+
hashie (5.0.0)
|
12
18
|
inifile (3.0.0)
|
13
|
-
|
14
|
-
|
15
|
-
|
19
|
+
jwt (2.8.1)
|
20
|
+
base64
|
21
|
+
multi_xml (0.6.0)
|
22
|
+
net-http (0.4.1)
|
23
|
+
uri
|
24
|
+
oauth2 (2.0.9)
|
25
|
+
faraday (>= 0.17.3, < 3.0)
|
26
|
+
jwt (>= 1.0, < 3.0)
|
27
|
+
multi_xml (~> 0.5)
|
28
|
+
rack (>= 1.2, < 4)
|
29
|
+
snaky_hash (~> 2.0)
|
30
|
+
version_gem (~> 1.1)
|
31
|
+
parallel (1.24.0)
|
32
|
+
parser (3.3.0.5)
|
16
33
|
ast (~> 2.4.1)
|
34
|
+
racc
|
35
|
+
racc (1.7.3)
|
36
|
+
rack (3.0.10)
|
17
37
|
rainbow (3.1.1)
|
18
38
|
rake (13.0.6)
|
19
|
-
regexp_parser (2.
|
20
|
-
rexml (3.2.
|
39
|
+
regexp_parser (2.9.0)
|
40
|
+
rexml (3.2.6)
|
21
41
|
rubocop (1.30.1)
|
22
42
|
parallel (~> 1.10)
|
23
43
|
parser (>= 3.1.0.0)
|
@@ -27,21 +47,26 @@ GEM
|
|
27
47
|
rubocop-ast (>= 1.18.0, < 2.0)
|
28
48
|
ruby-progressbar (~> 1.7)
|
29
49
|
unicode-display_width (>= 1.4.0, < 3.0)
|
30
|
-
rubocop-ast (1.
|
31
|
-
parser (>= 3.
|
50
|
+
rubocop-ast (1.31.2)
|
51
|
+
parser (>= 3.3.0.4)
|
32
52
|
rubocop-rake (0.6.0)
|
33
53
|
rubocop (~> 1.0)
|
34
|
-
ruby-progressbar (1.
|
35
|
-
|
54
|
+
ruby-progressbar (1.13.0)
|
55
|
+
snaky_hash (2.0.1)
|
56
|
+
hashie
|
57
|
+
version_gem (~> 1.1, >= 1.1.1)
|
58
|
+
unicode-display_width (2.5.0)
|
59
|
+
uri (0.13.0)
|
60
|
+
version_gem (1.1.4)
|
36
61
|
|
37
62
|
PLATFORMS
|
38
63
|
x86_64-linux
|
39
64
|
|
40
65
|
DEPENDENCIES
|
41
|
-
TTTrans!
|
42
66
|
rake (~> 13.0.6)
|
43
67
|
rubocop (~> 1.30.1)
|
44
68
|
rubocop-rake (~> 0.6.0)
|
69
|
+
tttrans!
|
45
70
|
|
46
71
|
BUNDLED WITH
|
47
72
|
2.3.7
|
data/README.md
CHANGED
@@ -18,20 +18,28 @@
|
|
18
18
|
|
19
19
|
$ gem install TTTrans
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
> **Warning**
|
22
|
+
>
|
23
|
+
> アプリケーションに追加しない場合はこの項目は無視してください。
|
24
|
+
>
|
25
|
+
> アプリケーションの Gemfile に次の行を追加します:
|
26
|
+
>
|
27
|
+
> ```ruby
|
28
|
+
> gem 'TTTrans'
|
29
|
+
> ```
|
30
|
+
>
|
31
|
+
> 次のコマンドを実行します:
|
32
|
+
>
|
33
|
+
> $ bundle install
|
30
34
|
|
31
35
|
### ログイン設定
|
32
36
|
API を利用するにはユーザー ID や API キーなどを設定する必要があるため、
|
33
37
|
`~/.tttconfig` に以下のように設定を書き込んでください。
|
34
38
|
|
39
|
+
> **Note**
|
40
|
+
>
|
41
|
+
> 「みんなの自動翻訳@TexTra®」にユーザー登録して、API キー等を取得してください。
|
42
|
+
|
35
43
|
```ini
|
36
44
|
[textra]
|
37
45
|
id=【TexTra に登録したユーザー ID】
|
@@ -41,7 +49,7 @@ api_secret=【API secret】
|
|
41
49
|
|
42
50
|
## 使用方法
|
43
51
|
|
44
|
-
`gem install` によってインストールを行った場合は、以下のコマンドで対話型翻訳を実行できます。
|
52
|
+
`gem install TTTrans` によってインストールを行った場合は、以下のコマンドで対話型翻訳を実行できます。
|
45
53
|
|
46
54
|
```bash
|
47
55
|
$ ttt
|
@@ -54,16 +62,17 @@ $ bundle # 1 回だけ
|
|
54
62
|
$ bundle exec ttt
|
55
63
|
```
|
56
64
|
|
57
|
-
`:en2ja` で 英日翻訳モード、`:ja2en`
|
65
|
+
対話中に `:en2ja` で 英日翻訳モード、`:ja2en` で日英翻訳モードの切り替えが可能です。
|
58
66
|
|
59
|
-
|
67
|
+
対話を終了するには、`:q` を入力するか、`Ctrl` + `C` を押してください。
|
60
68
|
|
61
69
|
## 開発について
|
62
70
|
|
63
71
|
リポジトリをチェックアウトした後、`bin/setup` を実行して依存関係をインストールします。
|
64
72
|
また、`bin/console` を実行してインタラクティブなプロンプトを表示し、実験を行うこともできます。
|
65
73
|
|
66
|
-
この
|
74
|
+
この Gem をローカルマシンにインストールするには、`bundle exec rake install` を実行します。
|
75
|
+
新しいバージョンをリリースするには、`version.rb` のバージョン番号を更新してから `bundle exec rake release` を実行します。
|
67
76
|
これによりそのバージョンの git タグが作成され、git コミットと作成されたタグがプッシュされ、
|
68
77
|
`.gem` ファイルが [rubygems.org](https://rubygems.org) に プッシュされます。
|
69
78
|
|
data/exe/ttt
CHANGED
@@ -4,6 +4,30 @@
|
|
4
4
|
require "tttrans"
|
5
5
|
require "inifile"
|
6
6
|
|
7
|
+
@i18n_list = {
|
8
|
+
"en": {
|
9
|
+
"En": " English: ",
|
10
|
+
"Ja": "Japanease: ",
|
11
|
+
"change_en_ja": "Change to English-Japanese translation",
|
12
|
+
"change_ja_en": "Change to Japanese-English translation",
|
13
|
+
"error_no_config": "Error: API key or user ID is not set\nCreate a configuration file in ~/.tttconfig"
|
14
|
+
},
|
15
|
+
"ja": {
|
16
|
+
"En": " 英語: ",
|
17
|
+
"Ja": "日本語: ",
|
18
|
+
"change_en_ja": "英日翻訳に変更します",
|
19
|
+
"change_ja_en": "日英翻訳に変更します",
|
20
|
+
"error_no_config": "エラー: API のキーまたはユーザー ID の設定がされていません\n~/.tttconfig に設定ファイルを作成してください"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
@lang = :en
|
25
|
+
@lang = :ja if ENV["LANG"].downcase =~ /ja/
|
26
|
+
|
27
|
+
def i18n(tag)
|
28
|
+
@i18n_list[@lang][tag]
|
29
|
+
end
|
30
|
+
|
7
31
|
# 設定があるか確認
|
8
32
|
def config_exists?(api_key, api_secret, user_id)
|
9
33
|
return true if [nil, ""].include?(api_key) \
|
@@ -26,14 +50,14 @@ end
|
|
26
50
|
envs = %w[TexTra_API_KEY TexTra_API_SECRET TexTra_ID].map do |item|
|
27
51
|
ENV[item]
|
28
52
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
53
|
+
|
54
|
+
api_key = envs[0] unless [nil, ""].include?(envs[0])
|
55
|
+
api_secret = envs[1] unless [nil, ""].include?(envs[1])
|
56
|
+
user_id = envs[2] unless [nil, ""].include?(envs[2])
|
32
57
|
|
33
58
|
if config_exists?(api_key, api_secret, user_id)
|
34
59
|
warn(
|
35
|
-
"\033[31m
|
36
|
-
"~/.tttconfig に設定ファイルを作成してください。\033[0m"
|
60
|
+
"\033[31m#{i18n(:error_no_config)}\033[0m"
|
37
61
|
)
|
38
62
|
exit(false)
|
39
63
|
end
|
@@ -42,8 +66,8 @@ token = TTTrans.token(api_key, api_secret)
|
|
42
66
|
|
43
67
|
mode = :en2ja
|
44
68
|
modes = {
|
45
|
-
en2ja: [
|
46
|
-
ja2en: [
|
69
|
+
en2ja: [i18n(:En), i18n(:Ja)],
|
70
|
+
ja2en: [i18n(:Ja), i18n(:En)]
|
47
71
|
}
|
48
72
|
|
49
73
|
loop do
|
@@ -55,14 +79,14 @@ loop do
|
|
55
79
|
end
|
56
80
|
|
57
81
|
if input.eql?(":en2ja")
|
58
|
-
puts("ℹ️ \033[36m
|
82
|
+
puts("ℹ️ \033[36m#{i18n(:change_en_ja)}\033[0m") if mode == :ja2en
|
59
83
|
mode = :en2ja
|
60
84
|
puts("-" * IO.console_size[1])
|
61
85
|
next
|
62
86
|
end
|
63
87
|
|
64
88
|
if input.eql?(":ja2en")
|
65
|
-
puts("ℹ️ \033[36m
|
89
|
+
puts("ℹ️ \033[36m#{i18n(:change_ja_en)}\033[0m") if mode == :en2ja
|
66
90
|
mode = :ja2en
|
67
91
|
puts("-" * IO.console_size[1])
|
68
92
|
next
|
@@ -70,7 +94,7 @@ loop do
|
|
70
94
|
|
71
95
|
next if input.eql?("")
|
72
96
|
|
73
|
-
break if
|
97
|
+
break if [":q", ":quit", ":exit"].include?(input)
|
74
98
|
|
75
99
|
puts("\033[32m#{modes[mode][1]}\033[1;32m#{TTTrans.translate(token, api_key, user_id, input, mode)}\033[0m")
|
76
100
|
puts("-" * IO.console_size[1])
|
data/lib/tttrans/version.rb
CHANGED
data/lib/tttrans.rb
CHANGED
@@ -3,19 +3,22 @@
|
|
3
3
|
require "readline"
|
4
4
|
require "io/console/size"
|
5
5
|
require "json"
|
6
|
-
require "
|
6
|
+
require "oauth2"
|
7
7
|
require_relative "tttrans/version"
|
8
|
+
require "net/http"
|
9
|
+
require "uri"
|
8
10
|
|
9
11
|
# TTTrans module
|
10
12
|
module TTTrans
|
11
13
|
class Error < StandardError; end
|
12
|
-
# Your code goes here...
|
13
14
|
|
14
|
-
def self.token(
|
15
|
-
|
16
|
-
|
15
|
+
def self.token(client_key, client_secret)
|
16
|
+
token_url = "https://mt-auto-minhon-mlt.ucri.jgn-x.jp/oauth2/token.php"
|
17
|
+
client = OAuth2::Client.new(client_key, client_secret, site: token_url)
|
18
|
+
client.client_credentials.get_token
|
17
19
|
end
|
18
20
|
|
21
|
+
# rubocop:disable Metrics/AbcSize
|
19
22
|
def self.translate(
|
20
23
|
token,
|
21
24
|
api_key,
|
@@ -23,21 +26,42 @@ module TTTrans
|
|
23
26
|
text,
|
24
27
|
mode = :en2ja
|
25
28
|
)
|
29
|
+
url = "https://mt-auto-minhon-mlt.ucri.jgn-x.jp/api/?"
|
26
30
|
case mode
|
27
31
|
when :en2ja
|
28
|
-
|
32
|
+
api_param = "generalNT_en_ja"
|
29
33
|
when :ja2en
|
30
|
-
|
34
|
+
api_param = "generalNT_ja_en"
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
body = {
|
38
|
+
"access_token" => token.token,
|
39
|
+
"key" => api_key,
|
40
|
+
"name" => user_id,
|
41
|
+
"type" => "json",
|
42
|
+
"text" => text,
|
43
|
+
"api_param" => api_param,
|
44
|
+
"api_name" => "mt"
|
45
|
+
}
|
46
|
+
|
47
|
+
response = Net::HTTP.post_form(URI.parse(url), body)
|
48
|
+
|
49
|
+
result = JSON.parse(response.body)
|
50
|
+
txt = ""
|
51
|
+
resultset = result["resultset"]
|
52
|
+
if resultset
|
53
|
+
code = resultset["code"]
|
54
|
+
if [501, 510].include?(code)
|
55
|
+
return "\e[31;1mERROR (#{code})#{resultset["message"] == "" ? "" : ": #{resultset["message"]}"}\e[0m"
|
56
|
+
end
|
57
|
+
|
58
|
+
begin
|
59
|
+
txt = resultset["result"]["text"]
|
60
|
+
rescue StandardError
|
61
|
+
txt = "\e[31;1mERROR (#{code})\e[0m"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
txt
|
42
65
|
end
|
66
|
+
# rubocop:enable Metrics/AbcSize
|
43
67
|
end
|
data/tttrans.gemspec
CHANGED
@@ -8,20 +8,15 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["MURATA Mitsuharu"]
|
9
9
|
spec.email = ["hikari.photon+dev@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
|
11
|
+
spec.summary = "This is a translation tool that uses the みんなの自動翻訳@TexTra® API."
|
12
|
+
spec.description = "#{spec.summary}\n「みんなの自動翻訳」and「TexTra」are registered trademarks of the NICT."
|
13
13
|
spec.homepage = "https://github.com/himeyama/tttrans/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.6.0"
|
16
16
|
|
17
|
-
# spec.metadata["allowed_push_host"] =
|
18
|
-
|
19
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
22
19
|
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
20
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
21
|
`git ls-files -z`.split("\x0").reject do |f|
|
27
22
|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
@@ -31,13 +26,9 @@ Gem::Specification.new do |spec|
|
|
31
26
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
27
|
spec.require_paths = ["lib"]
|
33
28
|
|
34
|
-
# Uncomment to register a new dependency of your gem
|
35
29
|
spec.add_dependency "inifile", "~> 3.0.0"
|
36
|
-
spec.add_dependency "
|
30
|
+
spec.add_dependency "oauth2", "~> 2.0"
|
37
31
|
spec.add_development_dependency "rake", "~> 13.0.6"
|
38
32
|
spec.add_development_dependency "rubocop", "~> 1.30.1"
|
39
33
|
spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
|
40
|
-
|
41
|
-
# For more information and examples about making a new gem, check out our
|
42
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
43
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: TTTrans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 24.03.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MURATA Mitsuharu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inifile
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: oauth2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,9 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.6.0
|
83
|
-
description:
|
83
|
+
description: |-
|
84
|
+
This is a translation tool that uses the みんなの自動翻訳@TexTra® API.
|
85
|
+
「みんなの自動翻訳」and「TexTra」are registered trademarks of the NICT.
|
84
86
|
email:
|
85
87
|
- hikari.photon+dev@gmail.com
|
86
88
|
executables:
|
@@ -120,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
- !ruby/object:Gem::Version
|
121
123
|
version: '0'
|
122
124
|
requirements: []
|
123
|
-
rubygems_version: 3.3
|
125
|
+
rubygems_version: 3.5.3
|
124
126
|
signing_key:
|
125
127
|
specification_version: 4
|
126
|
-
summary:
|
128
|
+
summary: This is a translation tool that uses the みんなの自動翻訳@TexTra® API.
|
127
129
|
test_files: []
|