habluhablu 0.2.6 → 0.4.1

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: 622b7f9e835ed5d23abdd90daceb817bf116d62b2d591fbdc777b3b17144c660
4
- data.tar.gz: c0568cd89ad6c6afac070cc44b592d858cf4797611b213465ffd2b42e6e42f00
3
+ metadata.gz: 5eb7be9baf82d77daac09b933e1307d67a2d84e9a28ddc71779c6c2a719a0bd9
4
+ data.tar.gz: 7c618006ba9ee8784378dd1fa5560ee2f22c18a207cabc1abf48d5729479ca43
5
5
  SHA512:
6
- metadata.gz: 5f42d1dbbab0fb5731853625e801443ad4e226dfa0c99a686a2b33a4b86aaf0724ad0159b4e3812e2f17ae0d2ab47d9f260223427a32486c869958467b6f97d2
7
- data.tar.gz: ea018c7e91a3cd8033eb357a4303327fc45406822f0ba074d80fe15befb1e654bc3d8bbddbff6cd58bf25d5429f3cfdb93091b98b1ce97bed22e57f29102cbb0
6
+ metadata.gz: 103bc857b0d829c13561efd325fb9babe8a418970d2f45d6c320bbd04d5d26076db230ebbd80579d6b6fd1f5b52fd154aabeede2987d7e2cdb91a35cd25c4e75
7
+ data.tar.gz: fd84e12afac9ac8e4169117befa1f497565fbad9862a41d53037230462c4c87dcfef2462a621ef6b9ceb05eff386506305106987be381fefb0a222ef5a715ef2
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
@@ -48,3 +50,15 @@ Style/OptionalBooleanParameter:
48
50
  Exclude:
49
51
  - 'lib/languages/languages.rb'
50
52
  - 'lib/habluhablu.rb'
53
+
54
+ Style/FormatStringToken:
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,55 +1,55 @@
1
- PATH
2
- remote: .
3
- specs:
4
- habluhablu (0.2.6)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.2)
10
- diff-lcs (1.4.4)
11
- parallel (1.20.1)
12
- parser (3.0.1.1)
13
- ast (~> 2.4.1)
14
- rainbow (3.0.0)
15
- rake (13.0.3)
16
- regexp_parser (2.1.1)
17
- rexml (3.2.5)
18
- rspec (3.10.0)
19
- rspec-core (~> 3.10.0)
20
- rspec-expectations (~> 3.10.0)
21
- rspec-mocks (~> 3.10.0)
22
- rspec-core (3.10.1)
23
- rspec-support (~> 3.10.0)
24
- rspec-expectations (3.10.1)
25
- diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.10.0)
27
- rspec-mocks (3.10.2)
28
- diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.10.0)
30
- rspec-support (3.10.2)
31
- rubocop (1.14.0)
32
- parallel (~> 1.10)
33
- parser (>= 3.0.0.0)
34
- rainbow (>= 2.2.2, < 4.0)
35
- regexp_parser (>= 1.8, < 3.0)
36
- rexml
37
- rubocop-ast (>= 1.5.0, < 2.0)
38
- ruby-progressbar (~> 1.7)
39
- unicode-display_width (>= 1.4.0, < 3.0)
40
- rubocop-ast (1.5.0)
41
- parser (>= 3.0.1.1)
42
- ruby-progressbar (1.11.0)
43
- unicode-display_width (2.0.0)
44
-
45
- PLATFORMS
46
- x64-mingw32
47
-
48
- DEPENDENCIES
49
- habluhablu!
50
- rake (~> 13.0)
51
- rspec (~> 3.0)
52
- rubocop (~> 1.7)
53
-
54
- BUNDLED WITH
55
- 2.2.14
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ habluhablu (0.4.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.20.1)
12
+ parser (3.0.1.1)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.3)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.2)
31
+ rubocop (1.14.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.5.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.5.0)
41
+ parser (>= 3.0.1.1)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.0.0)
44
+
45
+ PLATFORMS
46
+ x64-mingw32
47
+
48
+ DEPENDENCIES
49
+ habluhablu!
50
+ rake (~> 13.0)
51
+ rspec (~> 3.0)
52
+ rubocop (~> 1.7)
53
+
54
+ BUNDLED WITH
55
+ 2.2.14
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ ---
2
+ translation: "¡Hola!"
@@ -0,0 +1,16 @@
1
+ ---
2
+ iw:
3
+ welcome: שלום
4
+ registration: הירשם
5
+ log_in: להתחבר
6
+ log_in_with: "%{replace}התחבר ל"
7
+ log_out: להתנתק
8
+ email_address: אימייל
9
+ username: שם משתמש
10
+ password: סיסמה
11
+ remember_me: זכור אותי
12
+ forgot_password: שכחת את הסיסמא?
13
+ do_not_have_account: אין לך חשבון?
14
+ lorem: כדי יסוד מונחים מועמדים של, דת דפים מאמרשיחהצפה זאת. אתה דת שונה כלשהו, גם
15
+ אחר ליום בשפות, או ניווט פולנית לחיבור ארץ. ויש בקלות ואמנות אירועים או, אל אינו
16
+ כלכלה שתי.
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|
@@ -11,34 +12,53 @@ OptionParser.new do |opts|
11
12
  opts.on("-l", "--language SYMBOL", "Symbol of the language you want to generate file for (en, es, ...).")
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).")
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")
14
19
  end.parse!(into: args)
15
20
 
16
- if args[:multi].nil?
17
- if args[:keyword].nil?
18
- Habluhablu.hablu(args[:language])
19
- if File.exist?("config/locales/#{args[:language]}.yml")
20
- puts "..."
21
- sleep 0.5
22
- puts "Everything was generated successfully!"
23
- else
24
- puts "Something went wrong!"
25
- end
26
- else
27
- Habluhablu.keyword(args[:keyword])
21
+ information = lambda do |param|
22
+ if File.exist?("config/locales/#{param}.yml")
28
23
  puts "..."
29
24
  sleep 0.5
30
- puts "Everything was added successfully!"
25
+ puts "Everything was generated successfully!"
26
+ else
27
+ puts "Something went wrong!"
31
28
  end
32
- else
29
+ end
30
+
31
+ if args[:translate].nil? == false
32
+ if args[:from].nil? == false
33
+ translator = Translation.new(args[:translate], args[:target])
34
+ else
35
+ translator = Translation.new(args[:translate], args[:target], args[:from])
36
+ end
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
33
54
  languages_array = args[:multi].split("_")
34
55
  languages_array.each do |language|
35
56
  Habluhablu.hablu(language)
36
57
  end
37
- if File.exist?("config/locales/#{languages_array.last}.yml")
38
- puts "..."
39
- sleep 0.5
40
- puts "Everything was generated successfully!"
41
- else
42
- puts "Something went wrong!"
43
- end
58
+ information.call(languages_array.last)
59
+ end
60
+
61
+ if args[:sample].nil? == false
62
+ Habluhablu.render_sample(args[:sample])
63
+ information.call("sample")
44
64
  end
data/lib/habluhablu.rb CHANGED
@@ -14,6 +14,13 @@ module Habluhablu
14
14
  end
15
15
  end
16
16
 
17
+ # Cutom error with helpful message
18
+ class NoSampleError < Error
19
+ def initialize
20
+ super("There is no sample.yml file!")
21
+ end
22
+ end
23
+
17
24
  # Cutom error with helpful message
18
25
  class GemI18nError < Error
19
26
  def initialize
@@ -49,4 +56,17 @@ module Habluhablu
49
56
  end
50
57
  end
51
58
  end
59
+
60
+ def self.render_sample(languages)
61
+ raise NoSampleError.new unless File.exist?("config/locales/sample.yml")
62
+
63
+ languages = languages.split("_")
64
+ languages.each do |language|
65
+ File.open("config/locales/sample.yml", "r") do |f|
66
+ File.open("config/locales/#{language}.yml", "a+") do |fl|
67
+ fl.write(f.read)
68
+ end
69
+ end
70
+ end
71
+ end
52
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Habluhablu
4
- VERSION = "0.2.6"
4
+ VERSION = "0.4.1"
5
5
  end
@@ -14,7 +14,7 @@ class Languages
14
14
  "welcome" => "مرحبا",
15
15
  "registration" => "عنوان البريد الإلكتروني",
16
16
  "log_in" => "تسجيل الدخول",
17
- "log_in_with" => "سجّل الدخول باستخدام حساب", # Example: 'with Facebook'
17
+ "log_in_with" => "%{replace} سجّل الدخول باستخدام حساب", # Example: 'with Facebook'
18
18
  "log_out" => "تسجيل الخروج",
19
19
  "email_address" => "عنوان البريد الإلكتروني",
20
20
  "username" => "اسم االمستخدم",
@@ -30,7 +30,7 @@ class Languages
30
30
  "welcome" => "Welcome",
31
31
  "registration" => "Registartion",
32
32
  "log_in" => "Log in",
33
- "log_in_with" => "Log in with", # Example: 'with Facebook'
33
+ "log_in_with" => "Log in with %{replace}", # Example: 'with Facebook'
34
34
  "log_out" => "Log out",
35
35
  "email_address" => "Email address",
36
36
  "username" => "Username",
@@ -54,7 +54,7 @@ class Languages
54
54
  "welcome" => "Bienvenido",
55
55
  "registration" => "Regístrate",
56
56
  "log_in" => "Iniciar sesión",
57
- "log_in_with" => "Iniciar sesión con", # Example: 'with Facebook'
57
+ "log_in_with" => "Iniciar sesión con %{replace}", # Example: 'with Facebook'
58
58
  "log_out" => "Cerrar la sesión",
59
59
  "email_address" => "Dirección de correo electrónico",
60
60
  "username" => "Nombre de usuario",
@@ -78,7 +78,7 @@ class Languages
78
78
  "welcome" => "Witaj",
79
79
  "registration" => "Zarejestruj się",
80
80
  "log_in" => "Zaloguj się",
81
- "log_in_with" => "Zaloguj się za pomocą", # Example: 'with Facebook'
81
+ "log_in_with" => "Zaloguj się za pomocą %{replace}", # Example: 'with Facebook'
82
82
  "log_out" => "Wyolguj się",
83
83
  "email_address" => "Adres email",
84
84
  "username" => "Nazwa użytkownika",
@@ -95,7 +95,7 @@ class Languages
95
95
  "welcome" => "שלום",
96
96
  "registration" => "הירשם",
97
97
  "log_in" => "להתחבר",
98
- "log_in_with" => "התחבר ל", # Example: 'with Facebook'
98
+ "log_in_with" => "%{replace}התחבר ל", # Example: 'with Facebook'
99
99
  "log_out" => "להתנתק",
100
100
  "email_address" => "אימייל",
101
101
  "username" => "שם משתמש",
@@ -111,7 +111,7 @@ class Languages
111
111
  "welcome" => "Bienvenu", # bienvenue female
112
112
  "registration" => "Créer un compte",
113
113
  "log_in" => "Connexion",
114
- "log_in_with" => "Se connecter avec", # Example: 'with Facebook'
114
+ "log_in_with" => "Se connecter avec %{replace}", # Example: 'with Facebook'
115
115
  "log_out" => "Déconnexion",
116
116
  "email_address" => "Adresse e-mail",
117
117
  "username" => "Nom d'utilisateur",
@@ -127,7 +127,7 @@ class Languages
127
127
  "welcome" => "Benvenuto", # benvenuta female
128
128
  "registration" => "Iscriviti",
129
129
  "log_in" => "Accedi",
130
- "log_in_with" => "Accedi con", # Example: 'with Facebook'
130
+ "log_in_with" => "Accedi con %{replace}", # Example: 'with Facebook'
131
131
  "log_out" => "Esci",
132
132
  "email_address" => "Indirizzo e-mail",
133
133
  "username" => "Nome utente",
@@ -143,7 +143,7 @@ class Languages
143
143
  "welcome" => "Willkommen",
144
144
  "registration" => "Registrieren",
145
145
  "log_in" => "Anmelden",
146
- "log_in_with" => "Anmeldung mit", # Example: 'with Facebook'
146
+ "log_in_with" => "Anmeldung mit %{replace}", # Example: 'with Facebook'
147
147
  "log_out" => "Abmelden",
148
148
  "email_address" => "E-Mail-Adresse",
149
149
  "username" => "Nutzername",
@@ -165,7 +165,7 @@ class Languages
165
165
  "welcome" => "Bem-vindo",
166
166
  "registration" => "Cadastrar",
167
167
  "log_in" => "Entrar",
168
- "log_in_with" => "Entrar com", # Example: 'with Facebook'
168
+ "log_in_with" => "Entrar com %{replace}", # Example: 'with Facebook'
169
169
  "log_out" => "Fazer logoff",
170
170
  "email_address" => "Endereço de E-mail",
171
171
  "username" => "Nome de usuário",
@@ -187,14 +187,14 @@ class Languages
187
187
  "welcome" => "Hoşgeldiniz",
188
188
  "registration" => "Kayıt Ol",
189
189
  "log_in" => "Giriş Yap",
190
- "log_in_with" => "FACEBOOK ile giriş yap", # Example: 'with Facebook', reaplce facebook!
190
+ "log_in_with" => "%{replace} ile giriş yap", # Example: 'with Facebook'!
191
191
  "log_out" => "Çıkış Yap",
192
192
  "email_address" => "E-posta Adresi",
193
193
  "username" => "Kullanıcı adı",
194
194
  "password" => "Şifre",
195
195
  "remember_me" => "Beni hatırla",
196
196
  "forgot_password" => "Şifreni Mi Unuttun?",
197
- "do_not_have_account" => "Bir FACEBOOK hesabın yok mu?", # Replace facebook!
197
+ "do_not_have_account" => "Bir %{tr_register} hesabın yok mu?", # Example: Facebook
198
198
  "lorem" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
199
199
  }
200
200
  },
@@ -0,0 +1,48 @@
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"] = 'ef9f61b3d0mshb95dcad44627e7cp176d4bjsn8f4d9e2a1706'
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)
40
+ content = content["data"]["translations"].first["translatedText"]
41
+ File.open("config/locales/#{@target}.yml", "a+") do |f|
42
+ f.write({ "translation" => content.to_s }.to_yaml)
43
+ end
44
+ end
45
+ end
46
+
47
+ tr = Translation.new("Hi_there", "es")
48
+ tr.response
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.2.6
4
+ version: 0.4.1
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,12 +31,17 @@ files:
31
31
  - Rakefile
32
32
  - bin/console
33
33
  - bin/setup
34
+ - config/api_key.txt
35
+ - config/locales/api_key.txt
36
+ - config/locales/es.yml
37
+ - config/locales/iw.yml
34
38
  - exe/habluhablu
35
39
  - habluhablu.gemspec
36
40
  - lib/habluhablu.rb
37
41
  - lib/habluhablu/version.rb
38
42
  - lib/languages/Countries_Flags.md
39
43
  - lib/languages/languages.rb
44
+ - lib/translation.rb
40
45
  homepage: https://github.com/patrickgramatowski/habluhablu_gem
41
46
  licenses:
42
47
  - MIT