habluhablu 0.3.0 → 0.4.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 +4 -4
- data/.rubocop.yml +12 -1
- data/Gemfile.lock +1 -1
- data/config/api_key.txt +0 -0
- data/config/locales/api_key.txt +0 -0
- data/exe/habluhablu +33 -17
- data/lib/habluhablu/version.rb +1 -1
- data/lib/translation.rb +44 -0
- metadata +5 -3
- data/config/locales/es.yml +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5eeda5ab3b0c8db00ff5d89fd5ad34481cff609006d0f131447bb77184f42cd
|
|
4
|
+
data.tar.gz: 92ef6aa02d3e9f5314fed6992e9366ed4ed585ccaa5e567452e48bc5c36e1c7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53f39f866cebaacec6ef834c2bdf652ce423bedf4bb0a26d06f481fba32705494b5b9b88e8e8773a101c6b517dd5885e96f458b2a4e53277234b689473b68cd1
|
|
7
|
+
data.tar.gz: c1adb985f2828efe2ebaa54fe16ad737e8dc74ceb4e502ce7b0600958e4fb902fba27faf2fccd86865f06c45bcf572d1701965084839709bfece2fca7bb2c07e
|
data/.rubocop.yml
CHANGED
|
@@ -11,6 +11,8 @@ Layout/EndOfLine:
|
|
|
11
11
|
Style/StringLiterals:
|
|
12
12
|
Enabled: true
|
|
13
13
|
EnforcedStyle: double_quotes
|
|
14
|
+
Exclude:
|
|
15
|
+
- 'lib/translation.rb'
|
|
14
16
|
|
|
15
17
|
Style/StringLiteralsInInterpolation:
|
|
16
18
|
Enabled: true
|
|
@@ -50,4 +52,13 @@ Style/OptionalBooleanParameter:
|
|
|
50
52
|
- 'lib/habluhablu.rb'
|
|
51
53
|
|
|
52
54
|
Style/FormatStringToken:
|
|
53
|
-
Enabled: false
|
|
55
|
+
Enabled: false
|
|
56
|
+
|
|
57
|
+
Style/GlobalVars:
|
|
58
|
+
Enabled: false
|
|
59
|
+
|
|
60
|
+
Metrics/AbcSize:
|
|
61
|
+
Enabled: false
|
|
62
|
+
|
|
63
|
+
Style/ConditionalAssignment:
|
|
64
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
data/config/api_key.txt
ADDED
|
File without changes
|
|
File without changes
|
data/exe/habluhablu
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require "optparse"
|
|
5
5
|
require "habluhablu"
|
|
6
|
+
require "translation"
|
|
6
7
|
|
|
7
8
|
args = {}
|
|
8
9
|
OptionParser.new do |opts|
|
|
@@ -12,6 +13,9 @@ OptionParser.new do |opts|
|
|
|
12
13
|
opts.on("-m", "--multi SYMBOLS", "Symbols of languages you want to generate files for (en es pl ar)")
|
|
13
14
|
opts.on("-k", "--keyword KEYWORD", "Add your own keyword for all language files (.yml).")
|
|
14
15
|
opts.on("-s", "--sample FILES", "Add your own sample for language files (.yml).")
|
|
16
|
+
opts.on("-t", "--translate TEXT", "Translation text example: Hello_world_test!")
|
|
17
|
+
opts.on("-f", "--from SYMBOL", "From example: en")
|
|
18
|
+
opts.on("-o", "--target SYMBOL", "Target language example: es")
|
|
15
19
|
end.parse!(into: args)
|
|
16
20
|
|
|
17
21
|
information = lambda do |param|
|
|
@@ -24,25 +28,37 @@ information = lambda do |param|
|
|
|
24
28
|
end
|
|
25
29
|
end
|
|
26
30
|
|
|
27
|
-
if args[:
|
|
28
|
-
if args[:
|
|
29
|
-
|
|
30
|
-
Habluhablu.hablu(args[:language])
|
|
31
|
-
information.call(args[:language])
|
|
32
|
-
else
|
|
33
|
-
Habluhablu.keyword(args[:keyword])
|
|
34
|
-
puts "..."
|
|
35
|
-
sleep 0.5
|
|
36
|
-
puts "Everything was added successfully!"
|
|
37
|
-
end
|
|
31
|
+
if args[:translate].nil? == false
|
|
32
|
+
if args[:from].nil? == false
|
|
33
|
+
translator = Translation.new(args[:translate], args[:target])
|
|
38
34
|
else
|
|
39
|
-
|
|
40
|
-
languages_array.each do |language|
|
|
41
|
-
Habluhablu.hablu(language)
|
|
42
|
-
end
|
|
43
|
-
information.call(languages_array.last)
|
|
35
|
+
translator = Translation.new(args[:translate], args[:target], args[:from])
|
|
44
36
|
end
|
|
45
|
-
|
|
37
|
+
end
|
|
38
|
+
translator.response
|
|
39
|
+
information.call(args[:target])
|
|
40
|
+
|
|
41
|
+
if args[:language].nil? == false
|
|
42
|
+
Habluhablu.hablu(args[:language])
|
|
43
|
+
information.call(args[:language])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if args[:keyword].nil? == false
|
|
47
|
+
Habluhablu.keyword(args[:keyword])
|
|
48
|
+
puts "..."
|
|
49
|
+
sleep 0.5
|
|
50
|
+
puts "Everything was added successfully!"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
if args[:multi].nil? == false
|
|
54
|
+
languages_array = args[:multi].split("_")
|
|
55
|
+
languages_array.each do |language|
|
|
56
|
+
Habluhablu.hablu(language)
|
|
57
|
+
end
|
|
58
|
+
information.call(languages_array.last)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if args[:sample].nil? == false
|
|
46
62
|
Habluhablu.render_sample(args[:sample])
|
|
47
63
|
information.call("sample")
|
|
48
64
|
end
|
data/lib/habluhablu/version.rb
CHANGED
data/lib/translation.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "json"
|
|
7
|
+
require "yaml"
|
|
8
|
+
|
|
9
|
+
# Class comment
|
|
10
|
+
class Translation
|
|
11
|
+
def initialize(text, target, source = "en")
|
|
12
|
+
@text = text.gsub("_", "%2C%20")
|
|
13
|
+
@target = target
|
|
14
|
+
@source = source
|
|
15
|
+
@url = URI("https://google-translate1.p.rapidapi.com/language/translate/v2")
|
|
16
|
+
|
|
17
|
+
@http = Net::HTTP.new(@url.host, @url.port)
|
|
18
|
+
@http.use_ssl = true
|
|
19
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
20
|
+
|
|
21
|
+
@request = Net::HTTP::Post.new(@url)
|
|
22
|
+
@request["content-type"] = "application/x-www-form-urlencoded"
|
|
23
|
+
@request["accept-encoding"] = "application/gzip"
|
|
24
|
+
File.open("config/locales/api_key.txt", "a+") do |f|
|
|
25
|
+
$KEY = f.read
|
|
26
|
+
end
|
|
27
|
+
if $KEY.length <= 2 || $KEY.nil?
|
|
28
|
+
@request["x-rapidapi-key"] = '069f34f2bamsha3ef70a3f7e20cap1dcfe9jsn2dcff8d20c4e'
|
|
29
|
+
else
|
|
30
|
+
@request["x-rapidapi-key"] = $KEY
|
|
31
|
+
end
|
|
32
|
+
@request["x-rapidapi-host"] = "google-translate1.p.rapidapi.com"
|
|
33
|
+
@request.body = "q=#{@text}!&target=#{@target}&source=#{@source}"
|
|
34
|
+
# Example "q=Hello%2C%20dear%2C%20friend!&target=es&source=en"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def response
|
|
38
|
+
response = @http.request(@request)
|
|
39
|
+
content = JSON.parse(response.read_body)["data"]["translations"].first["translatedText"]
|
|
40
|
+
File.open("config/locales/#{@target}.yml", "a+") do |f|
|
|
41
|
+
f.write({ "Translation" => content }.to_yaml)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: habluhablu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrick Gramatowski
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-05-
|
|
11
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Generate language file (for I18n) with translations of the most useful
|
|
14
14
|
phrases.
|
|
@@ -31,7 +31,8 @@ files:
|
|
|
31
31
|
- Rakefile
|
|
32
32
|
- bin/console
|
|
33
33
|
- bin/setup
|
|
34
|
-
- config/
|
|
34
|
+
- config/api_key.txt
|
|
35
|
+
- config/locales/api_key.txt
|
|
35
36
|
- config/locales/iw.yml
|
|
36
37
|
- exe/habluhablu
|
|
37
38
|
- habluhablu.gemspec
|
|
@@ -39,6 +40,7 @@ files:
|
|
|
39
40
|
- lib/habluhablu/version.rb
|
|
40
41
|
- lib/languages/Countries_Flags.md
|
|
41
42
|
- lib/languages/languages.rb
|
|
43
|
+
- lib/translation.rb
|
|
42
44
|
homepage: https://github.com/patrickgramatowski/habluhablu_gem
|
|
43
45
|
licenses:
|
|
44
46
|
- MIT
|
data/config/locales/es.yml
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
es:
|
|
3
|
-
date:
|
|
4
|
-
months_names:
|
|
5
|
-
- Enero
|
|
6
|
-
- Febrero
|
|
7
|
-
- Marzo
|
|
8
|
-
- Abril
|
|
9
|
-
- Mayo
|
|
10
|
-
- Junio
|
|
11
|
-
- Julio
|
|
12
|
-
- Agosto
|
|
13
|
-
- Septiembre
|
|
14
|
-
- Octubre
|
|
15
|
-
- Noviembre
|
|
16
|
-
- Dieciembre
|
|
17
|
-
abbr_month_names:
|
|
18
|
-
- Ene
|
|
19
|
-
- Feb
|
|
20
|
-
- Mar
|
|
21
|
-
- Abr
|
|
22
|
-
- May
|
|
23
|
-
- Jun
|
|
24
|
-
- Jul
|
|
25
|
-
- Ago
|
|
26
|
-
- Set
|
|
27
|
-
- Oct
|
|
28
|
-
- Nov
|
|
29
|
-
- Dic
|
|
30
|
-
welcome: Bienvenido
|
|
31
|
-
registration: Regístrate
|
|
32
|
-
log_in: Iniciar sesión
|
|
33
|
-
log_in_with: Iniciar sesión con %{replace}
|
|
34
|
-
log_out: Cerrar la sesión
|
|
35
|
-
email_address: Dirección de correo electrónico
|
|
36
|
-
username: Nombre de usuario
|
|
37
|
-
password: Contraseña
|
|
38
|
-
remember_me: Recordarme
|
|
39
|
-
forgot_password: "¿Has olvidado tu contraseña?"
|
|
40
|
-
do_not_have_account: "¿No tienes una cuenta?"
|
|
41
|
-
lorem: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
|
42
|
-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
|
43
|
-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
|
|
44
|
-
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
|
|
45
|
-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
|
|
46
|
-
deserunt mollit anim id est laborum.
|