habluhablu 0.2.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile.lock +1 -1
- data/config/api_key.txt +0 -0
- data/config/locales/api_key.txt +0 -0
- data/config/locales/iw.yml +16 -0
- data/exe/habluhablu +41 -21
- data/lib/habluhablu.rb +20 -0
- data/lib/habluhablu/version.rb +1 -1
- data/lib/languages/languages.rb +52 -9
- data/lib/translation.rb +44 -0
- metadata +6 -2
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
|
@@ -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
data/config/api_key.txt
ADDED
File without changes
|
File without changes
|
@@ -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
|
-
|
17
|
-
if
|
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
|
25
|
+
puts "Everything was generated successfully!"
|
26
|
+
else
|
27
|
+
puts "Something went wrong!"
|
31
28
|
end
|
32
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
data/lib/habluhablu/version.rb
CHANGED
data/lib/languages/languages.rb
CHANGED
@@ -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",
|
@@ -152,7 +152,50 @@ class Languages
|
|
152
152
|
"forgot_password" => "Passwort vergessen?",
|
153
153
|
"do_not_have_account" => "Hast du noch kein FACEBOOK-Konto?", # Change facebook!
|
154
154
|
"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."
|
155
|
-
|
155
|
+
}
|
156
|
+
},
|
157
|
+
pt: {
|
158
|
+
"pt" => {
|
159
|
+
"date" => {
|
160
|
+
"months_names" => %w[
|
161
|
+
],
|
162
|
+
"abbr_month_names" => %w[
|
163
|
+
]
|
164
|
+
},
|
165
|
+
"welcome" => "Bem-vindo",
|
166
|
+
"registration" => "Cadastrar",
|
167
|
+
"log_in" => "Entrar",
|
168
|
+
"log_in_with" => "Entrar com %{replace}", # Example: 'with Facebook'
|
169
|
+
"log_out" => "Fazer logoff",
|
170
|
+
"email_address" => "Endereço de E-mail",
|
171
|
+
"username" => "Nome de usuário",
|
172
|
+
"password" => "Senha",
|
173
|
+
"remember_me" => "Lembrar de mim",
|
174
|
+
"forgot_password" => "Esqueceu Sua Senha",
|
175
|
+
"do_not_have_account" => "Não tem uma conta da?", # Example: da Facebook
|
176
|
+
"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."
|
177
|
+
}
|
178
|
+
},
|
179
|
+
tr: {
|
180
|
+
"tr" => {
|
181
|
+
"date" => {
|
182
|
+
"months_names" => %w[
|
183
|
+
],
|
184
|
+
"abbr_month_names" => %w[
|
185
|
+
]
|
186
|
+
},
|
187
|
+
"welcome" => "Hoşgeldiniz",
|
188
|
+
"registration" => "Kayıt Ol",
|
189
|
+
"log_in" => "Giriş Yap",
|
190
|
+
"log_in_with" => "%{replace} ile giriş yap", # Example: 'with Facebook'!
|
191
|
+
"log_out" => "Çıkış Yap",
|
192
|
+
"email_address" => "E-posta Adresi",
|
193
|
+
"username" => "Kullanıcı adı",
|
194
|
+
"password" => "Şifre",
|
195
|
+
"remember_me" => "Beni hatırla",
|
196
|
+
"forgot_password" => "Şifreni Mi Unuttun?",
|
197
|
+
"do_not_have_account" => "Bir %{tr_register} hesabın yok mu?", # Example: Facebook
|
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."
|
156
199
|
}
|
157
200
|
},
|
158
201
|
example: {
|
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,12 +31,16 @@ 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/iw.yml
|
34
37
|
- exe/habluhablu
|
35
38
|
- habluhablu.gemspec
|
36
39
|
- lib/habluhablu.rb
|
37
40
|
- lib/habluhablu/version.rb
|
38
41
|
- lib/languages/Countries_Flags.md
|
39
42
|
- lib/languages/languages.rb
|
43
|
+
- lib/translation.rb
|
40
44
|
homepage: https://github.com/patrickgramatowski/habluhablu_gem
|
41
45
|
licenses:
|
42
46
|
- MIT
|