habluhablu 0.5.7 → 0.5.8

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: 8d1f721e948bfa1a1bf2d9d6de0cf494471cc88be928b361ac948ea52549961a
4
- data.tar.gz: 3a04f76784dcde5a5ca4d12337983492c8080f4c72e55ee51d8c1e12854c5b38
3
+ metadata.gz: 0b0ab7b1bf0eff39d9728b8dfa084c141a875834476ab75979e312ccce3d0992
4
+ data.tar.gz: ed07ad6442164b97452b77d02181726e3c0ad1cd13e3f5c97be967bc168e4319
5
5
  SHA512:
6
- metadata.gz: e8e19e9a36b8e4bca9819d4f0beb2f4d321777c4fcad4fde7f7d4e56b2dfd3ee93256d2480ae698791281d74692a9742d01006e552c2f276e128cbc51b6b7452
7
- data.tar.gz: 726d7e05aac708ceca016e6e20d88921c87ddfe7379d015479b5edc4876e33b6540e55fd5384639839b61036c53513f60e991878dec358892145ab84de2396a8
6
+ metadata.gz: bd18d45a2dbee563cd070477dcd37351b702c7c9a573b72fa9fc9a7cf66f976035878eacd7dc1a45420c2297a90ada99c6902349e9e005d230da5e72a3840dec
7
+ data.tar.gz: f420e01ca997baeb742c78bdd09dddfde5c9609a8b9376bf3bc0a745cb6e5afea87609658278be66b27352c72774e6098e0642ca10646518e95ebaa77c9cc801
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- ## [Unreleased]
1
+ ## [0.5.8] - 2022-01-10
2
+
3
+ - Updates CHANGELOG
4
+ - Refactores some parts of code
5
+
6
+ # [0.1.1]-[0.5.7] 2021-05-05 - 2021-06-13
7
+
8
+ - Adds new languages
9
+ - Integrates gem to be able to use Google Translate API
10
+ - Improves documentation
11
+ - Adds specs
12
+ - Adds the ability to generate language files in different formats
2
13
 
3
14
  ## [0.1.0] - 2021-05-05
4
15
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- habluhablu (0.5.7)
4
+ habluhablu (0.5.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -21,6 +21,7 @@ What about ancient languages? :scroll:
21
21
  - Portuguese
22
22
  - Turkish
23
23
  - Polish
24
+ - Hungarian
24
25
  - Thai (th - symbol)
25
26
  - Chinese (zh - symbol)
26
27
  - Arabic
@@ -61,7 +62,7 @@ To generate a keyword for all languages files use: `habluhablu -k <keyword>` com
61
62
 
62
63
  To translate a phrase/word use: `habluhablu -t hello_world -f en -o es`, where the command translates 'hello there' to spanish (-o flag).
63
64
 
64
- **Important!** to use translator you will have to create an account [Google API](https://rapidapi.com/googlecloud/api/google-translate1) and put api_key into api_key.txt file in config/locales directory.
65
+ **Important!** to use translator you will have to create an account [Google API](https://rapidapi.com/googlecloud/api/google-translate1) and set the api key as ENV variable - `ENV['HABLUHABLU_API_KEY']`
65
66
 
66
67
  If you want to generate your own sample for languages files, You can do it by:
67
68
  - creating your own sample.yml file in config/locales directory
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Habluhablu
4
- VERSION = "0.5.7"
4
+ VERSION = "0.5.8"
5
5
  end
data/lib/habluhablu.rb CHANGED
@@ -7,6 +7,13 @@ require_relative "languages/languages"
7
7
  module Habluhablu
8
8
  class Error < StandardError; end
9
9
 
10
+ # Raise error if wrong language symbol passed
11
+ class NoLanguageSymbolYet < Error
12
+ def initialize
13
+ super("No language in the lib (YET!)")
14
+ end
15
+ end
16
+
10
17
  # Cutom error with helpful message
11
18
  class WrongSymbolError < Error
12
19
  def initialize(language)
@@ -363,10 +363,12 @@ class Languages
363
363
  end
364
364
 
365
365
  def include_language?
366
- @languages.key?(@language) ? true : false
366
+ @languages.key?(@language)
367
367
  end
368
368
 
369
369
  def render
370
- @languages.key?(@language) ? @languages[@language].to_yaml : "No language in the lib (YET!)"
370
+ raise Habluhablu::NoLanguageSymbolYet.new unless @languages.key?(@language)
371
+
372
+ @languages[@language].to_yaml
371
373
  end
372
374
  end
data/lib/translation.rb CHANGED
@@ -21,13 +21,13 @@ class Translation
21
21
  @request = Net::HTTP::Post.new(@url)
22
22
  @request["content-type"] = "application/x-www-form-urlencoded"
23
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?
24
+
25
+ @key = ENV['HABLUHABLU_API_KEY']
26
+
27
+ if @key.nil?
28
28
  @request["x-rapidapi-key"] = 'Add your google api key!'
29
29
  else
30
- @request["x-rapidapi-key"] = $KEY
30
+ @request["x-rapidapi-key"] = @key
31
31
  end
32
32
  @request["x-rapidapi-host"] = "google-translate1.p.rapidapi.com"
33
33
  @request.body = "q=#{@text}!&target=#{@target}&source=#{@source}"
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.5.7
4
+ version: 0.5.8
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-06-13 00:00:00.000000000 Z
11
+ date: 2022-01-10 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.