TTTrans 0.2.2 → 24.03.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd875cf64e830b987af63dd436e0c92ca377bb548f7e93102ccb2b5f8fcb8b56
4
- data.tar.gz: 19a4082dbda971e05e3b6057d83f4bd17bfd1207e033a19d63964c5454939a29
3
+ metadata.gz: 5dfc529c1f1edbc1c44d5cf405126da41a83f860c95042a7a7f77850f57a09d6
4
+ data.tar.gz: 5a51bd707ef25939a93d5d0b6cfd9aeff9be1317f6ee21499f930cfc1dafaf2b
5
5
  SHA512:
6
- metadata.gz: e463fec650fc09fbe1ff7fe63956af83670d267f2336c5a492cedd2aa02bb2a3230d09be74d225b6f6bd5b00002c661c38f8ecc2d9b42fdacbb1adc8e196231b
7
- data.tar.gz: 31d6e7315c19786c7b6d6e1569a79dca1054544d9ffc8890c95bc8c8ad478bed4c62c14d2108358b019438a0419fd5f7abbabf13da3492ab665d4829d05e9ef6
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
- TTTrans (0.2.2)
4
+ tttrans (24.03.31)
5
5
  inifile (~> 3.0.0)
6
- oauth (~> 0.5.10)
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
- oauth (0.5.10)
14
- parallel (1.22.1)
15
- parser (3.1.2.0)
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.5.0)
20
- rexml (3.2.5)
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.18.0)
31
- parser (>= 3.1.1.0)
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.11.0)
35
- unicode-display_width (2.1.0)
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
- アプリケーションの Gemfile に次の行を追加します (アプリケーションに追加しない場合は無視してください):
22
-
23
- ```ruby
24
- gem 'TTTrans'
25
- ```
26
-
27
- 次のコマンドを実行します (アプリケーションに追加しない場合は無視してください):
28
-
29
- $ bundle install
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
- `:q` または、`Ctrl` + `C` で対話を終了します。
67
+ 対話を終了するには、`:q` を入力するか、`Ctrl` + `C` を押してください。
60
68
 
61
69
  ## 開発について
62
70
 
63
71
  リポジトリをチェックアウトした後、`bin/setup` を実行して依存関係をインストールします。
64
72
  また、`bin/console` を実行してインタラクティブなプロンプトを表示し、実験を行うこともできます。
65
73
 
66
- このgemをローカルマシンにインストールするには、`bundle exec rake install` を実行します。新しいバージョンをリリースするには、`version.rb` のバージョン番号を更新してから `bundle exec rake release` を実行します。
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) \
@@ -33,8 +57,7 @@ user_id = envs[2] unless [nil, ""].include?(envs[2])
33
57
 
34
58
  if config_exists?(api_key, api_secret, user_id)
35
59
  warn(
36
- "\033[31mエラー: API のキーまたはユーザー ID の設定がされていません。" \
37
- "~/.tttconfig に設定ファイルを作成してください。\033[0m"
60
+ "\033[31m#{i18n(:error_no_config)}\033[0m"
38
61
  )
39
62
  exit(false)
40
63
  end
@@ -43,8 +66,8 @@ token = TTTrans.token(api_key, api_secret)
43
66
 
44
67
  mode = :en2ja
45
68
  modes = {
46
- en2ja: [" English: ", "Japanese: "],
47
- ja2en: ["Japanese: ", " English: "]
69
+ en2ja: [i18n(:En), i18n(:Ja)],
70
+ ja2en: [i18n(:Ja), i18n(:En)]
48
71
  }
49
72
 
50
73
  loop do
@@ -56,14 +79,14 @@ loop do
56
79
  end
57
80
 
58
81
  if input.eql?(":en2ja")
59
- puts("ℹ️ \033[36m英日翻訳に変更します\033[0m") if mode == :ja2en
82
+ puts("ℹ️ \033[36m#{i18n(:change_en_ja)}\033[0m") if mode == :ja2en
60
83
  mode = :en2ja
61
84
  puts("-" * IO.console_size[1])
62
85
  next
63
86
  end
64
87
 
65
88
  if input.eql?(":ja2en")
66
- puts("ℹ️ \033[36m日英翻訳に変更します\033[0m") if mode == :en2ja
89
+ puts("ℹ️ \033[36m#{i18n(:change_ja_en)}\033[0m") if mode == :en2ja
67
90
  mode = :ja2en
68
91
  puts("-" * IO.console_size[1])
69
92
  next
@@ -71,7 +94,7 @@ loop do
71
94
 
72
95
  next if input.eql?("")
73
96
 
74
- break if input.eql?(":q")
97
+ break if [":q", ":quit", ":exit"].include?(input)
75
98
 
76
99
  puts("\033[32m#{modes[mode][1]}\033[1;32m#{TTTrans.translate(token, api_key, user_id, input, mode)}\033[0m")
77
100
  puts("-" * IO.console_size[1])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TTTrans
4
- VERSION = "0.2.2"
4
+ VERSION = "24.03.31"
5
5
  end
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 "oauth"
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(api_key, api_secret)
15
- consumer = OAuth::Consumer.new(api_key, api_secret)
16
- OAuth::AccessToken.new(consumer)
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
- url = "https://mt-auto-minhon-mlt.ucri.jgn-x.jp/api/mt/generalNT_en_ja/"
32
+ api_param = "generalNT_en_ja"
29
33
  when :ja2en
30
- url = "https://mt-auto-minhon-mlt.ucri.jgn-x.jp/api/mt/generalNT_ja_en/"
34
+ api_param = "generalNT_ja_en"
31
35
  end
32
36
 
33
- response = token.post(
34
- url, {
35
- key: api_key,
36
- type: "json",
37
- name: user_id,
38
- text: text
39
- }
40
- )
41
- JSON.parse(response.body)["resultset"]["result"]["text"]
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 = "Interactive Translation App"
12
- # spec.description =
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 "oauth", "~> 0.5.10"
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: 0.2.2
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: 2022-06-24 00:00:00.000000000 Z
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: oauth
28
+ name: oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.10
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.5.10
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.7
125
+ rubygems_version: 3.5.3
124
126
  signing_key:
125
127
  specification_version: 4
126
- summary: Interactive Translation App
128
+ summary: This is a translation tool that uses the みんなの自動翻訳@TexTra® API.
127
129
  test_files: []