habluhablu 0.3.0 → 0.5.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: 74cc8fdd9b2fe0b2cb45b4457eec91c27745560026c457856b068d47f8d9ea47
4
- data.tar.gz: 12e305f318399b37b365bb6914e14a47dd09ef17b98bffe0c4a476ca1cd8c436
3
+ metadata.gz: 7eed0b9343162e21a5494ad84ae29f33aab82f52ba4df5350c631cd134bf2a6d
4
+ data.tar.gz: e5a54c5b427bb3792cb4369b6f38bfa8da7c3fbc6d12ca3e1e1b71e52878f3bf
5
5
  SHA512:
6
- metadata.gz: 5d4e5b984fb6bcf5948dca8fefddfa391fbb3b17efc8a1e8957f0e0b1150e88c9a8f45e32fe2675e6c53613c3b3d34175a01bdbab3cb13e30c6414b493f4fcf9
7
- data.tar.gz: edd8228e983a65532bea4d576df2be32f9693c97b60943b242d3d3c74b3b3f41bece5faf1855b52988636f1ede4ef8e8e404774f7839f2cb34499fb433a70cd8
6
+ metadata.gz: 01cb6ad52bd398d61c1864303f8ac8f7073fd45170c9c16ea4ac0d645b96ea458b35f5eaefc12040276e5aa497bdae44277d042086b301b69cb04d544b36182a
7
+ data.tar.gz: ba01336399138153c09802390791ddcfe5a2f31b314d2594269b44e3c3ee31facdae115f9480926b02ad69052d7b5fc92fc66a27e45c84675e14830a75b41490
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.5.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,6 +27,7 @@ es:
27
27
  - Oct
28
28
  - Nov
29
29
  - Dic
30
+ language: Español
30
31
  welcome: Bienvenido
31
32
  registration: Regístrate
32
33
  log_in: Iniciar sesión
@@ -37,10 +38,12 @@ es:
37
38
  password: Contraseña
38
39
  remember_me: Recordarme
39
40
  forgot_password: "¿Has olvidado tu contraseña?"
40
- do_not_have_account: "¿No tienes una cuenta?"
41
+ do_not_have_account: "¿No tienes una cuenta en %{register}?"
41
42
  lorem: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
42
43
  incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
43
44
  exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
44
45
  irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
45
46
  pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
46
47
  deserunt mollit anim id est laborum.
48
+ ---
49
+ translation: "¡amigo!"
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  iw:
3
+ language: עִברִית
3
4
  welcome: שלום
4
5
  registration: הירשם
5
6
  log_in: להתחבר
@@ -10,7 +11,7 @@ iw:
10
11
  password: סיסמה
11
12
  remember_me: זכור אותי
12
13
  forgot_password: שכחת את הסיסמא?
13
- do_not_have_account: אין לך חשבון?
14
+ do_not_have_account: "%{register} אין לך חשבון?"
14
15
  lorem: כדי יסוד מונחים מועמדים של, דת דפים מאמרשיחהצפה זאת. אתה דת שונה כלשהו, גם
15
16
  אחר ליום בשפות, או ניווט פולנית לחיבור ארץ. ויש בקלות ואמנות אירועים או, אל אינו
16
17
  כלכלה שתי.
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,10 +13,14 @@ 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")
19
+ opts.on("-j", "--json SYMBOL", "Render languages' json files.")
15
20
  end.parse!(into: args)
16
21
 
17
- information = lambda do |param|
18
- if File.exist?("config/locales/#{param}.yml")
22
+ information = lambda do |param, exe|
23
+ if File.exist?("config/locales/#{param}.#{exe}")
19
24
  puts "..."
20
25
  sleep 0.5
21
26
  puts "Everything was generated successfully!"
@@ -24,25 +29,42 @@ information = lambda do |param|
24
29
  end
25
30
  end
26
31
 
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
32
+ if args[:json].nil? == false
33
+ Languages.new("en").render_json(args[:json])
34
+ information.call(args[:json].split("_").first, "json")
35
+ end
36
+
37
+ if args[:translate].nil? == false
38
+ if args[:from].nil? == false
39
+ translator = Translation.new(args[:translate], args[:target])
38
40
  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)
41
+ translator = Translation.new(args[:translate], args[:target], args[:from])
44
42
  end
45
- else
43
+ translator.response
44
+ information.call(args[:target], "yml")
45
+ end
46
+
47
+ if args[:language].nil? == false
48
+ Habluhablu.hablu(args[:language])
49
+ information.call(args[:language], "yml")
50
+ end
51
+
52
+ if args[:keyword].nil? == false
53
+ Habluhablu.keyword(args[:keyword])
54
+ puts "..."
55
+ sleep 0.5
56
+ puts "Everything was added successfully!"
57
+ end
58
+
59
+ if args[:multi].nil? == false
60
+ languages_array = args[:multi].split("_")
61
+ languages_array.each do |language|
62
+ Habluhablu.hablu(language)
63
+ end
64
+ information.call(languages_array.last, "yml")
65
+ end
66
+
67
+ if args[:sample].nil? == false
46
68
  Habluhablu.render_sample(args[:sample])
47
- information.call("sample")
69
+ information.call("sample", "yml")
48
70
  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.5.1"
5
5
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yaml"
4
+ require_relative "render_json"
4
5
 
5
6
  # Class comment
6
7
  class Languages
8
+ include RenderJson
7
9
  attr_writer :languages
8
10
 
9
11
  def initialize(language)
@@ -11,6 +13,7 @@ class Languages
11
13
  @languages = {
12
14
  ar: {
13
15
  "ar" => {
16
+ "language" => "العربية",
14
17
  "welcome" => "مرحبا",
15
18
  "registration" => "عنوان البريد الإلكتروني",
16
19
  "log_in" => "تسجيل الدخول",
@@ -21,12 +24,13 @@ class Languages
21
24
  "password" => "كلمه المرور",
22
25
  "remember_me" => "تذكرنى",
23
26
  "forgot_password" => "نسيت كلمة مرورك",
24
- "do_not_have_account" => "ليس لديك حساب؟",
27
+ "do_not_have_account" => "ليس لديك حساب على {register}%؟",
25
28
  "lorem" => "غينيا واستمر العصبة ضرب قد. وباءت الأمريكي الأوربيين هو به،, هو العالم، الثقيلة بال. مع وايرلندا الأوروبيّون كان, قد بحق أسابيع العظمى واعتلاء. انه كل وإقامة المواد. "
26
29
  }
27
30
  },
28
31
  en: {
29
32
  "en" => {
33
+ "language" => "English",
30
34
  "welcome" => "Welcome",
31
35
  "registration" => "Registartion",
32
36
  "log_in" => "Log in",
@@ -37,7 +41,7 @@ class Languages
37
41
  "password" => "Password",
38
42
  "remember_me" => "Remember me",
39
43
  "forgot_password" => "Forgot password?",
40
- "do_not_have_account" => "Don't You have an account?",
44
+ "do_not_have_account" => "Don't You have an %{register} account?",
41
45
  "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."
42
46
  }
43
47
  },
@@ -51,6 +55,7 @@ class Languages
51
55
  Ene Feb Mar Abr May Jun Jul Ago Set Oct Nov Dic
52
56
  ]
53
57
  },
58
+ "language" => "Español",
54
59
  "welcome" => "Bienvenido",
55
60
  "registration" => "Regístrate",
56
61
  "log_in" => "Iniciar sesión",
@@ -61,7 +66,7 @@ class Languages
61
66
  "password" => "Contraseña",
62
67
  "remember_me" => "Recordarme",
63
68
  "forgot_password" => "¿Has olvidado tu contraseña?",
64
- "do_not_have_account" => "¿No tienes una cuenta?",
69
+ "do_not_have_account" => "¿No tienes una cuenta en %{register}?",
65
70
  "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."
66
71
  }
67
72
  },
@@ -75,6 +80,7 @@ class Languages
75
80
  Sty Lut Mar Kwi Maj Cze Lip Sie Wrz Paź Lis Gru
76
81
  ]
77
82
  },
83
+ "language" => "Polski",
78
84
  "welcome" => "Witaj",
79
85
  "registration" => "Zarejestruj się",
80
86
  "log_in" => "Zaloguj się",
@@ -85,13 +91,14 @@ class Languages
85
91
  "password" => "Hasło",
86
92
  "remember_me" => "Zapamiętaj mnie!",
87
93
  "forgot_password" => "Zapomniałeś hasła?",
88
- "do_not_have_account" => "Nie masz jeszcze konta?",
94
+ "do_not_have_account" => "Nie masz jeszcze konta w ${register}?",
89
95
  "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."
90
96
  }
91
97
  },
92
98
  iw: {
93
99
  "iw" => {
94
100
  # I'm not sure about this translation, it has to be checked!!
101
+ "language" => "עִברִית",
95
102
  "welcome" => "שלום",
96
103
  "registration" => "הירשם",
97
104
  "log_in" => "להתחבר",
@@ -102,12 +109,13 @@ class Languages
102
109
  "password" => "סיסמה",
103
110
  "remember_me" => "זכור אותי",
104
111
  "forgot_password" => "שכחת את הסיסמא?",
105
- "do_not_have_account" => "אין לך חשבון?",
112
+ "do_not_have_account" => "%{register} אין לך חשבון?",
106
113
  "lorem" => "כדי יסוד מונחים מועמדים של, דת דפים מאמרשיחהצפה זאת. אתה דת שונה כלשהו, גם אחר ליום בשפות, או ניווט פולנית לחיבור ארץ. ויש בקלות ואמנות אירועים או, אל אינו כלכלה שתי."
107
114
  }
108
115
  },
109
116
  fr: {
110
117
  "fr" => {
118
+ "language" => "Français",
111
119
  "welcome" => "Bienvenu", # bienvenue female
112
120
  "registration" => "Créer un compte",
113
121
  "log_in" => "Connexion",
@@ -118,12 +126,13 @@ class Languages
118
126
  "password" => "Mot de passe",
119
127
  "remember_me" => "Mémoriser",
120
128
  "forgot_password" => "Mot de passe oublié",
121
- "do_not_have_account" => "Vous n'avez pas de compte?",
129
+ "do_not_have_account" => "Vous n'avez pas de compte %{register}?",
122
130
  "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."
123
131
  }
124
132
  },
125
133
  it: {
126
134
  "it" => {
135
+ "language" => "Italiano",
127
136
  "welcome" => "Benvenuto", # benvenuta female
128
137
  "registration" => "Iscriviti",
129
138
  "log_in" => "Accedi",
@@ -134,12 +143,13 @@ class Languages
134
143
  "password" => "Password",
135
144
  "remember_me" => "Ricordami",
136
145
  "forgot_password" => "Ho dimenticato la password",
137
- "do_not_have_account" => "Non possiedi un account?",
146
+ "do_not_have_account" => "Non possiedi un account %{register}?",
138
147
  "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."
139
148
  }
140
149
  },
141
150
  de: {
142
151
  "de" => {
152
+ "language" => "Deutsch",
143
153
  "welcome" => "Willkommen",
144
154
  "registration" => "Registrieren",
145
155
  "log_in" => "Anmelden",
@@ -150,10 +160,44 @@ class Languages
150
160
  "password" => "Passwort",
151
161
  "remember_me" => "Merken",
152
162
  "forgot_password" => "Passwort vergessen?",
153
- "do_not_have_account" => "Hast du noch kein FACEBOOK-Konto?", # Change facebook!
163
+ "do_not_have_account" => "Hast du noch kein %{replace}-Konto?", # Change!
154
164
  "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
165
  }
156
166
  },
167
+ ru: {
168
+ "ru" => {
169
+ "language" => "Русский",
170
+ "welcome" => "Добро пожаловать",
171
+ "registration" => "Зарегистрироваться",
172
+ "log_in" => "Вход",
173
+ "log_in_with" => "Войти с помощью %{replace}", # Example: 'with Facebook'
174
+ "log_out" => "Выйти",
175
+ "email_address" => "Адрес электронной почты",
176
+ "username" => "имя пользователя",
177
+ "password" => "Пароль",
178
+ "remember_me" => "Запомнить меня",
179
+ "forgot_password" => "Забыли пароль",
180
+ "do_not_have_account" => "У вас нет учётной записи %{register}?", # Change facebook!
181
+ "lorem" => "Лорем ипсум долор сит амет, пер цлита поссит ех, ат мунере фабулас петентиум сит. Иус цу цибо саперет сцрипсерит, нец виси муциус лабитур ид. Ет хис нонумес нолуиссе дигниссим."
182
+ }
183
+ },
184
+ ja: {
185
+ "ja" => {
186
+ "language" => "日本語",
187
+ "welcome" => "ようこそ",
188
+ "registration" => "サインアップ",
189
+ "log_in" => "サインイン",
190
+ "log_in_with" => "%{replace}でサインインする", # Example: 'with Facebook'
191
+ "log_out" => "サインアウト",
192
+ "email_address" => "メールアドレス",
193
+ "username" => "ユーザー名",
194
+ "password" => "パスワード",
195
+ "remember_me" => "パスワードを記憶する",
196
+ "forgot_password" => "パスワードを忘れた場合",
197
+ "do_not_have_account" => "%{register}アカウントをお持ちではありませんか??", # Change facebook!
198
+ "lorem" => "旅ロ京青利セムレ弱改フヨス波府かばぼ意送でぼ調掲察たス日西重ケアナ住橋ユムミク順待ふかんぼ人奨貯鏡すびそ。"
199
+ }
200
+ },
157
201
  pt: {
158
202
  "pt" => {
159
203
  "date" => {
@@ -162,6 +206,7 @@ class Languages
162
206
  "abbr_month_names" => %w[
163
207
  ]
164
208
  },
209
+ "language" => "Português",
165
210
  "welcome" => "Bem-vindo",
166
211
  "registration" => "Cadastrar",
167
212
  "log_in" => "Entrar",
@@ -172,7 +217,7 @@ class Languages
172
217
  "password" => "Senha",
173
218
  "remember_me" => "Lembrar de mim",
174
219
  "forgot_password" => "Esqueceu Sua Senha",
175
- "do_not_have_account" => "Não tem uma conta da?", # Example: da Facebook
220
+ "do_not_have_account" => "Não tem uma conta da %{register}?", # Example: da Facebook
176
221
  "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
222
  }
178
223
  },
@@ -184,6 +229,7 @@ class Languages
184
229
  "abbr_month_names" => %w[
185
230
  ]
186
231
  },
232
+ "language" => "Türkçe",
187
233
  "welcome" => "Hoşgeldiniz",
188
234
  "registration" => "Kayıt Ol",
189
235
  "log_in" => "Giriş Yap",
@@ -194,10 +240,33 @@ class Languages
194
240
  "password" => "Şifre",
195
241
  "remember_me" => "Beni hatırla",
196
242
  "forgot_password" => "Şifreni Mi Unuttun?",
197
- "do_not_have_account" => "Bir %{tr_register} hesabın yok mu?", # Example: Facebook
243
+ "do_not_have_account" => "Bir %{register} hesabın yok mu?", # Example: Facebook
198
244
  "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
245
  }
200
246
  },
247
+ ko: {
248
+ "ko" => {
249
+ "date" => {
250
+ "months_names" => %w[
251
+ ],
252
+ "abbr_month_names" => %w[
253
+ ]
254
+ },
255
+ "language" => "한국어",
256
+ "welcome" => "안녕하세요",
257
+ "registration" => "가입",
258
+ "log_in" => "로그인",
259
+ "log_in_with" => "%{replace}으로 로그인", # Example: 'with Facebook' carefully!
260
+ "log_out" => "로그아웃",
261
+ "email_address" => "이메일 주소",
262
+ "username" => "사용자 이름",
263
+ "password" => "비밀번호",
264
+ "remember_me" => "사용자 이름 저장",
265
+ "forgot_password" => "비밀번호를 잊으셨나요?",
266
+ "do_not_have_account" => "%{register}계정이 없으신가요?",
267
+ "lorem" => "국민경제의 발전을 위한 중요정책의 수립에 관하여 대통령의 자문에 응하기 위하여 국민경제자문회의를 둘 수 있다."
268
+ }
269
+ },
201
270
  example: {
202
271
  "example" => {
203
272
  "date" => {
@@ -206,6 +275,7 @@ class Languages
206
275
  "abbr_month_names" => %w[
207
276
  ]
208
277
  },
278
+ "language" => "",
209
279
  "welcome" => "",
210
280
  "registration" => "",
211
281
  "log_in" => "",
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ # Class comment
6
+ module RenderJson
7
+ def render_json(languages_input)
8
+ # "ar" || "ar_iw_pl"
9
+ languages_input = languages_input.split("_")
10
+ languages_input.each do |language|
11
+ next unless @languages.key?(language.to_sym)
12
+
13
+ File.open("config/locales/#{language}.json", "a+") do |f|
14
+ f.write(@languages[language.to_sym].to_json)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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.3.0
4
+ version: 0.5.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-14 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.
@@ -39,6 +39,8 @@ files:
39
39
  - lib/habluhablu/version.rb
40
40
  - lib/languages/Countries_Flags.md
41
41
  - lib/languages/languages.rb
42
+ - lib/languages/render_json.rb
43
+ - lib/translation.rb
42
44
  homepage: https://github.com/patrickgramatowski/habluhablu_gem
43
45
  licenses:
44
46
  - MIT