light_tr 1.0.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +95 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/trans +39 -0
- data/lib/light_tr/commands.rb +116 -0
- data/lib/light_tr/config.rb +65 -0
- data/lib/light_tr/runner.rb +16 -0
- data/lib/light_tr/store.rb +36 -0
- data/lib/light_tr/translator.rb +46 -0
- data/lib/light_tr/version.rb +5 -0
- data/lib/light_tr.rb +12 -0
- data/light_tr.gemspec +34 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fefec0155db0e698e81b29f9260d2b4fb844b3ec2a148fa1d7f419bbdf6d9b71
|
4
|
+
data.tar.gz: 266422371befd490f89cc0b918eab19be2b103c414710a40e9931300e6a99291
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b48c7b2ff2f42bb22c2487026ae5856af6a73671baa898b4eac0bef35ac788de87d33c42aeac9be50de5a23037be2b124135f0ff6aea46f1a93a3e1751d7c29a
|
7
|
+
data.tar.gz: ccb46e927dbaa8aea893017f5ec63d4b25f2e8e30cf8d94c23613986a56d384e03b760aa1ecb4024e057835f3628bbbf6393c0af976cffdf79054084ac175038
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
light_tr (1.0.0)
|
5
|
+
awesome_print (~> 1.2)
|
6
|
+
executable (~> 1.2)
|
7
|
+
hashie (~> 2.1)
|
8
|
+
lockbox (~> 0.6)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
ast (2.4.2)
|
14
|
+
awesome_print (1.9.2)
|
15
|
+
coderay (1.1.3)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
executable (1.2.1)
|
18
|
+
ffi (1.15.4)
|
19
|
+
formatador (0.3.0)
|
20
|
+
guard (2.18.0)
|
21
|
+
formatador (>= 0.2.4)
|
22
|
+
listen (>= 2.7, < 4.0)
|
23
|
+
lumberjack (>= 1.0.12, < 2.0)
|
24
|
+
nenv (~> 0.1)
|
25
|
+
notiffany (~> 0.0)
|
26
|
+
pry (>= 0.13.0)
|
27
|
+
shellany (~> 0.0)
|
28
|
+
thor (>= 0.18.1)
|
29
|
+
guard-rspec (0.7.3)
|
30
|
+
guard (>= 0.10.0)
|
31
|
+
hashie (2.1.2)
|
32
|
+
listen (3.7.0)
|
33
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
34
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
35
|
+
lockbox (0.6.6)
|
36
|
+
lumberjack (1.2.8)
|
37
|
+
method_source (1.0.0)
|
38
|
+
nenv (0.3.0)
|
39
|
+
notiffany (0.1.3)
|
40
|
+
nenv (~> 0.1)
|
41
|
+
shellany (~> 0.0)
|
42
|
+
parallel (1.21.0)
|
43
|
+
parser (3.0.2.0)
|
44
|
+
ast (~> 2.4.1)
|
45
|
+
pry (0.14.1)
|
46
|
+
coderay (~> 1.1)
|
47
|
+
method_source (~> 1.0)
|
48
|
+
rainbow (3.0.0)
|
49
|
+
rake (13.0.6)
|
50
|
+
rb-fsevent (0.11.0)
|
51
|
+
rb-inotify (0.10.1)
|
52
|
+
ffi (~> 1.0)
|
53
|
+
regexp_parser (2.1.1)
|
54
|
+
rexml (3.2.5)
|
55
|
+
rspec (3.10.0)
|
56
|
+
rspec-core (~> 3.10.0)
|
57
|
+
rspec-expectations (~> 3.10.0)
|
58
|
+
rspec-mocks (~> 3.10.0)
|
59
|
+
rspec-core (3.10.1)
|
60
|
+
rspec-support (~> 3.10.0)
|
61
|
+
rspec-expectations (3.10.1)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.10.0)
|
64
|
+
rspec-mocks (3.10.2)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.10.0)
|
67
|
+
rspec-support (3.10.3)
|
68
|
+
rubocop (1.22.3)
|
69
|
+
parallel (~> 1.10)
|
70
|
+
parser (>= 3.0.0.0)
|
71
|
+
rainbow (>= 2.2.2, < 4.0)
|
72
|
+
regexp_parser (>= 1.8, < 3.0)
|
73
|
+
rexml
|
74
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
75
|
+
ruby-progressbar (~> 1.7)
|
76
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
77
|
+
rubocop-ast (1.13.0)
|
78
|
+
parser (>= 3.0.1.1)
|
79
|
+
ruby-progressbar (1.11.0)
|
80
|
+
shellany (0.0.1)
|
81
|
+
thor (1.1.0)
|
82
|
+
unicode-display_width (2.1.0)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
arm64-darwin-20
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
guard-rspec (~> 0)
|
89
|
+
light_tr!
|
90
|
+
rake (~> 13.0)
|
91
|
+
rspec (~> 3.0)
|
92
|
+
rubocop (~> 1.7)
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.2.22
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Paweł Niemczyk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# LightTr
|
2
|
+
|
3
|
+
This is simple wrapper on Google translate API
|
4
|
+
Happy Translate!
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'light_tr'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install light_tr
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
After instalation you can use `trans` as executable command line tool.
|
25
|
+
|
26
|
+
Check what you can do via
|
27
|
+
`trans -help`
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/light_tr.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "light_tr"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/trans
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'light_tr'
|
3
|
+
command = ARGV[0].to_s.strip
|
4
|
+
|
5
|
+
return LightTr::Commands.command_runner '-config' if LightTr::Config.config_missing?
|
6
|
+
return LightTr::Commands.command_runner(command) if LightTr::Commands.command?(command)
|
7
|
+
|
8
|
+
raise LightTr::Error, "Please put some text!" if ARGV[0].nil?
|
9
|
+
|
10
|
+
override_language = /^\-[a-zA-Z]{2}$/.match(command)
|
11
|
+
languages = (override_language ? ARGV[0].strip[1..2] : LightTr::Config.languages).split(',').map(&:strip)
|
12
|
+
full_text = (override_language ? ARGV[1..] : ARGV).join(' ')
|
13
|
+
store = LightTr::Store.new(name: 'translations', file_path: LightTr::Config.config_path)
|
14
|
+
translator = LightTr::Translator.new(LightTr::Config.api_key)
|
15
|
+
text = full_text.gsub(/[[:space:]]+/, ' ').strip
|
16
|
+
interactive = command == '-i'
|
17
|
+
|
18
|
+
unless text.empty?
|
19
|
+
runner = LightTr::Runner.new(store, translator)
|
20
|
+
return puts runner.translate(languages[0], text) if languages.count == 1
|
21
|
+
languages.each { |target| puts "#{target.upcase}: #{runner.translate(target, text)}" }
|
22
|
+
end
|
23
|
+
|
24
|
+
if interactive
|
25
|
+
puts 'Interactive mode! (quit by /q or empty line)'
|
26
|
+
puts 'Type any sentence now:'
|
27
|
+
|
28
|
+
loop do
|
29
|
+
text = STDIN.gets.chomp.to_s.gsub(/[[:space:]]+/, ' ').strip
|
30
|
+
break if text == '/q' || text.empty?
|
31
|
+
|
32
|
+
runner = LightTr::Runner.new(store, translator)
|
33
|
+
return puts " " + runner.translate(languages[0], text) if languages.count == 1
|
34
|
+
languages.each { |target| puts " #{target.upcase}: #{runner.translate(target, text)}" }
|
35
|
+
puts "\n"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
LightTr::Commands.print_footer
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'fileutils'
|
3
|
+
require 'lockbox'
|
4
|
+
|
5
|
+
module LightTr
|
6
|
+
class Commands
|
7
|
+
SUPPORTED_LANGUAGES = %w[
|
8
|
+
af ga sq it ar ja az kn eu ko bn la be lv bg lt ca mk ms mt hr no cs fa da pl nl pt en ro eo
|
9
|
+
ru et sr tl sk fi sl fr es gl sw ka sv de ta el te gu th ht tr iw uk hi ur hu vi is cy id yi
|
10
|
+
zh-CN zh-TW
|
11
|
+
]
|
12
|
+
COMMANDS_MAPPING = {
|
13
|
+
'-config' => 'update_config',
|
14
|
+
'-show_config' => 'show_config',
|
15
|
+
'-clear_cache' => 'clear_cache',
|
16
|
+
'-supported_languages' => 'supported_languages',
|
17
|
+
'-help' => 'help'
|
18
|
+
}
|
19
|
+
|
20
|
+
def self.command?(command)
|
21
|
+
COMMANDS_MAPPING.include?(command)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.command_runner(command)
|
25
|
+
method_name = COMMANDS_MAPPING[command]
|
26
|
+
send(method_name)
|
27
|
+
print_footer
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.print_footer
|
31
|
+
puts "\nLight Translate © 2021 by Paweł Niemczyk"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.help
|
35
|
+
puts "usage: trans [options] any sentence"
|
36
|
+
puts "\noptions:"
|
37
|
+
puts ' -config : init configuration'
|
38
|
+
puts ' -show_config : show configuration'
|
39
|
+
puts ' -clear_cache : clear translation cache'
|
40
|
+
puts ' -pl : translate only one language (pl can be changed on any supported language)'
|
41
|
+
puts ' -i : run translator in interactive mode'
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.clear_cache
|
45
|
+
cache_file = File.join(::LightTr::Config.config_path, 'tanslations.yml')
|
46
|
+
File.delete(cache_file) if File.exist?(cache_file)
|
47
|
+
puts 'Cache cleared !!!'
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.show_config
|
51
|
+
api_key = ::LightTr::Config.api_key
|
52
|
+
show_key = api_key[..10] + ('*' * (api_key.size - 10))
|
53
|
+
puts 'Current configuration:'
|
54
|
+
puts "\nlanguages : #{::LightTr::Config.languages}"
|
55
|
+
puts "Goggle Translate API key : #{show_key}\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.supported_languages
|
59
|
+
puts 'Supported languages (codes):'
|
60
|
+
puts SUPPORTED_LANGUAGES.join(', ')
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.languages_valid?(languages)
|
64
|
+
prepare_languages(languages).all? do |code|
|
65
|
+
SUPPORTED_LANGUAGES.include?(code)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.languages_errors_and_update_config(languages)
|
70
|
+
prepare_languages(languages).each do |code|
|
71
|
+
puts "Incorrect language code: #{code}" unless SUPPORTED_LANGUAGES.include?(code)
|
72
|
+
end
|
73
|
+
puts "\n"
|
74
|
+
supported_languages
|
75
|
+
puts "\nTry again :D\n\n"
|
76
|
+
update_config
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.prepare_languages(value)
|
80
|
+
value.to_s.split(',').map(&:strip).compact
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.update_config
|
84
|
+
FileUtils.mkdir_p(::LightTr::Config.config_path) unless File.directory?(::LightTr::Config.config_path)
|
85
|
+
puts 'Hello my friend lets setup Light Translator now!'
|
86
|
+
puts 'We will need only two things, Google Translate API key and your favorite languages'
|
87
|
+
puts "When you complete setup in your home directory will be created .light_tr/.config file with encrypted configuration"
|
88
|
+
puts "\nLet's add Google Translate API key first. Instructions on: https://cloud.google.com/translate/docs/quickstarts"
|
89
|
+
print 'Give me the Google Translate API key: '
|
90
|
+
api_key = STDIN.gets.chomp
|
91
|
+
|
92
|
+
puts "\nlanguages example: pl, en, ru"
|
93
|
+
print 'Give me languages: '
|
94
|
+
languages = prepare_languages(STDIN.gets.chomp).join(', ')
|
95
|
+
|
96
|
+
puts "\nYour configuration is:"
|
97
|
+
puts "API key: #{api_key}"
|
98
|
+
puts "languages: #{languages}\n\n"
|
99
|
+
|
100
|
+
return languages_errors_and_update_config(languages) unless languages_valid?(languages)
|
101
|
+
|
102
|
+
print "It's correct? (y/n/q): "
|
103
|
+
answer = STDIN.gets.chomp
|
104
|
+
|
105
|
+
return update_config if answer.strip == 'n'
|
106
|
+
return puts 'Bye Bye !' if answer.strip == 'q'
|
107
|
+
|
108
|
+
master_key = Lockbox.generate_key
|
109
|
+
::LightTr::Config.set({ 'master_key' => master_key })
|
110
|
+
::LightTr::Config.set({ 'api_key' => Lockbox.new(key: master_key).encrypt(api_key.strip) })
|
111
|
+
::LightTr::Config.set({ 'languages' => languages.strip })
|
112
|
+
|
113
|
+
puts "\nHappy translating!"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'lockbox'
|
5
|
+
|
6
|
+
module LightTr
|
7
|
+
class Config
|
8
|
+
class SetConfigError < StandardError; end
|
9
|
+
|
10
|
+
def self.languages
|
11
|
+
get['languages']
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.api_key
|
15
|
+
get['api_key'] || raise('Google Translation API key missing. Try to update configuration via `trans -config`')
|
16
|
+
master_key = get['master_key'] || raise('Config file corrupted. Try to update configuration via `trans -config`')
|
17
|
+
Lockbox.new(key: master_key).decrypt(get['api_key'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.config_path
|
21
|
+
File.join(Dir.home, '.light_tr')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config_exists?
|
25
|
+
File.exists?(config_file)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.config_missing?
|
29
|
+
!config_exists?
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.config_file
|
33
|
+
File.expand_path('.config', config_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get
|
37
|
+
return load_configuration if config_exists?
|
38
|
+
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.set(hash)
|
43
|
+
raise SetConfigError, 'argument is not kind of hash' unless hash.kind_of?(Hash)
|
44
|
+
|
45
|
+
updated_config = get.merge(hash)
|
46
|
+
save_configuration(updated_config)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.clear
|
50
|
+
File.write(config_file, {}.to_yaml)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.save_configuration(config)
|
56
|
+
File.write(config_file, config.to_yaml)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.load_configuration
|
60
|
+
YAML.load_file(config_file)
|
61
|
+
rescue
|
62
|
+
{}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LightTr
|
4
|
+
class Runner
|
5
|
+
def initialize(store, translator)
|
6
|
+
@store = store
|
7
|
+
@translator = translator
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :store, :translator
|
11
|
+
|
12
|
+
def translate(target, text)
|
13
|
+
store.load(target, text) || store.save(target, text, translator.translate(text, target))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module LightTr
|
6
|
+
class Store
|
7
|
+
def initialize(name:, file_name: nil, file_path: nil)
|
8
|
+
@name = name
|
9
|
+
file_name ||= "#{name.to_s.downcase}.yml"
|
10
|
+
file_path ||= file_path || Dir.pwd
|
11
|
+
@file = File.join(file_path, file_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :name, :file
|
15
|
+
|
16
|
+
def current
|
17
|
+
YAML.safe_load(File.read(file)) || {}
|
18
|
+
rescue StandardError => _e
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
def load(target, query)
|
23
|
+
(current[target] || {})[query.downcase]
|
24
|
+
end
|
25
|
+
|
26
|
+
def save(target, query, translation)
|
27
|
+
payload = current.merge(
|
28
|
+
target => (current[target] || {}).merge(
|
29
|
+
query.downcase => translation
|
30
|
+
)
|
31
|
+
)
|
32
|
+
File.open(file, 'w') { |f| YAML.dump(payload, f) }
|
33
|
+
translation
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module LightTr
|
8
|
+
class Translator
|
9
|
+
def initialize(api_key)
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def translate(query, target = 'en')
|
14
|
+
extract_translation(request(query, target))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :api_key
|
20
|
+
|
21
|
+
def request(query, target)
|
22
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
23
|
+
http.use_ssl = true
|
24
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
25
|
+
req.body = { q: query, target: target }.to_json
|
26
|
+
http.request(req)
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_translation(response)
|
30
|
+
translations = JSON.parse(response.body).dig('data', 'translations') || [{}]
|
31
|
+
translations.first['translatedText']
|
32
|
+
end
|
33
|
+
|
34
|
+
def uri
|
35
|
+
@uri ||= URI.parse("https://translation.googleapis.com/language/translate/v2?key=#{api_key}&format=text")
|
36
|
+
end
|
37
|
+
|
38
|
+
def headers
|
39
|
+
@headers ||= {
|
40
|
+
'Host': 'translation.googleapis.com',
|
41
|
+
'Content-Type': 'application/json; charset=utf-8',
|
42
|
+
'Accept': 'application/json'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/light_tr.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "light_tr/version"
|
4
|
+
require_relative "light_tr/config"
|
5
|
+
require_relative "light_tr/store"
|
6
|
+
require_relative "light_tr/translator"
|
7
|
+
require_relative "light_tr/runner"
|
8
|
+
require_relative "light_tr/commands"
|
9
|
+
|
10
|
+
module LightTr
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
data/light_tr.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/light_tr/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "light_tr"
|
7
|
+
spec.version = LightTr::VERSION
|
8
|
+
spec.authors = ["Paweł Niemczyk"]
|
9
|
+
spec.email = ["pawel@way2do.it"]
|
10
|
+
|
11
|
+
spec.summary = "Translate any word via Google Translate API"
|
12
|
+
spec.description = "Translate any word via Google Translate API"
|
13
|
+
spec.homepage = "https://github.com/pniemczyk/light_tr"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/pniemczyk/light_tr"
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency 'rspec', '~> 2.12'
|
28
|
+
spec.add_development_dependency 'guard-rspec', '~> 0'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_dependency 'hashie', '~> 2.1'
|
31
|
+
spec.add_dependency 'executable', '~> 1.2'
|
32
|
+
spec.add_dependency 'awesome_print', '~> 1.2'
|
33
|
+
spec.add_dependency 'lockbox', '~> 0.6'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: light_tr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Niemczyk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: executable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: awesome_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.2'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: lockbox
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.6'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.6'
|
111
|
+
description: Translate any word via Google Translate API
|
112
|
+
email:
|
113
|
+
- pawel@way2do.it
|
114
|
+
executables:
|
115
|
+
- trans
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- exe/trans
|
130
|
+
- lib/light_tr.rb
|
131
|
+
- lib/light_tr/commands.rb
|
132
|
+
- lib/light_tr/config.rb
|
133
|
+
- lib/light_tr/runner.rb
|
134
|
+
- lib/light_tr/store.rb
|
135
|
+
- lib/light_tr/translator.rb
|
136
|
+
- lib/light_tr/version.rb
|
137
|
+
- light_tr.gemspec
|
138
|
+
homepage: https://github.com/pniemczyk/light_tr
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata:
|
142
|
+
homepage_uri: https://github.com/pniemczyk/light_tr
|
143
|
+
source_code_uri: https://github.com/pniemczyk/light_tr
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.4.0
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubygems_version: 3.2.22
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Translate any word via Google Translate API
|
163
|
+
test_files: []
|