habluhablu 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74cc8fdd9b2fe0b2cb45b4457eec91c27745560026c457856b068d47f8d9ea47
4
- data.tar.gz: 12e305f318399b37b365bb6914e14a47dd09ef17b98bffe0c4a476ca1cd8c436
3
+ metadata.gz: e5eeda5ab3b0c8db00ff5d89fd5ad34481cff609006d0f131447bb77184f42cd
4
+ data.tar.gz: 92ef6aa02d3e9f5314fed6992e9366ed4ed585ccaa5e567452e48bc5c36e1c7f
5
5
  SHA512:
6
- metadata.gz: 5d4e5b984fb6bcf5948dca8fefddfa391fbb3b17efc8a1e8957f0e0b1150e88c9a8f45e32fe2675e6c53613c3b3d34175a01bdbab3cb13e30c6414b493f4fcf9
7
- data.tar.gz: edd8228e983a65532bea4d576df2be32f9693c97b60943b242d3d3c74b3b3f41bece5faf1855b52988636f1ede4ef8e8e404774f7839f2cb34499fb433a70cd8
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- habluhablu (0.3.0)
4
+ habluhablu (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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[:sample].nil?
28
- if args[:multi].nil?
29
- if args[:keyword].nil?
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
- languages_array = args[:multi].split("_")
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
- else
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Habluhablu
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -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.3.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 00:00:00.000000000 Z
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/locales/es.yml
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
@@ -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.