glossync 0.2.2 → 0.2.3

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: 8b3fca7e886ee98004c3a5294042a66e8c19d99959b5e6fa160423c5fbbbc8cf
4
- data.tar.gz: beb018ec951d554c688e791f8b4bc3681a2b8d24f15bc572d04bfb4ed721aa1b
3
+ metadata.gz: d9691ad226bb7f81bec886d45d957fabb312707ed74c0c21bdb65a9a83273420
4
+ data.tar.gz: 16f7f0279a84bc2419df6426a8212c1c746bc097ff2fd748c31f9ae562517f10
5
5
  SHA512:
6
- metadata.gz: 0a096bdba1209036d5ef2e19c905eac2f8a91b06d6c8786d950136c15f779d7654d4bf8ecc605b0e14e63eba17b2ffa0eef7043f7cf438acb04024f5fd77d9c4
7
- data.tar.gz: ea9431a5e8670775fd0c959adbc6c4249662cc5f849c0fbe234bac9fc1745734f4dfb2882c2d59dbb6fcbe9bec74b854387cc8ed48dfd887b7739c2051616092
6
+ metadata.gz: 3b673baf2a80741bb0e9e7b8fd5ab270bbfc4007821a27a454f81d5fcdf0ed80886844afcf7453f3a8c1d0f57b3ec8d5c8ed8d8ae451a004bd0d578dd24e6b3d
7
+ data.tar.gz: 5654114e854ad28c2b7b5e6f6054dda4c27037d85ad5fdfa12360452bcaef5bd9442087cbf0321a11db98482a1de9af7691dff5280a5a59d69c54fff9b78feb3
@@ -6,6 +6,8 @@ module Glossync
6
6
  base_locale: :en,
7
7
  }.freeze
8
8
 
9
+ # define convinence methods for each of the configuration paramaters special
10
+ # methods added for parameters that take booleans, e.g. dont_xxxx or xxxx!
9
11
  DEFAULT_CONFIG.each do |k, v|
10
12
  (case v
11
13
  when true, false
@@ -23,11 +25,14 @@ module Glossync
23
25
  end
24
26
 
25
27
  class << self
28
+ # A hash which stores all of Glossync's global options.
26
29
  attr_reader :options
27
30
 
31
+ # If called with a block, executes the block setting the argument to Glossync,
32
+ # else returns the options hash
28
33
  def config(&block)
29
- @options ||= {}
30
- block.call(Glossync)
34
+ @options ||= DEFAULT_CONFIG.clone
35
+ block_given? ? block.call(Glossync) : @options
31
36
  end
32
37
  end
33
38
  end
@@ -1,4 +1,6 @@
1
1
  module Glossync
2
+ # Raised if Glossync is used before a valid tl_store is set.
3
+ # @see Glossync#tl_store
2
4
  class NoTranslationStore < StandardError
3
5
  def initialize(*)
4
6
  super('please set Glossync.tl_store')
@@ -1,23 +1,42 @@
1
1
  module Glossync
2
+ # Holds various missing translation handlers. Any object is a missing
3
+ # translation handler if it responds to the method handle with an arity of 4
2
4
  module MissingTranslationHandler
5
+
6
+ # The default handler, simply returns the error message
3
7
  class Default
8
+ # handles an I18n MissingTranslation error
9
+ # @param error the error thrown by I18n, should always be a MissingTranslation
10
+ # @param who the self of the class that caught the error
11
+ # @param field the field that has a missing translation
12
+ # @param locale the locale that was being translated to
13
+ # @return [String]
4
14
  def handle(error, _who, _field, _locale)
5
15
  error.message
6
16
  end
7
17
  end
8
18
 
19
+ # Raises the error message
9
20
  class Raiser
21
+ # :nodoc:
10
22
  def handle(error, _, _, _)
11
23
  raise error
12
24
  end
13
25
  end
14
26
 
27
+ # This handler attempts to translate the given string to the target language using
28
+ # the Google Translate API
15
29
  class GoogleTranslate
30
+ # @param key the key for the Google Translate API
16
31
  def initialize(key)
17
32
  @api_key = key
18
33
  @cache = {}
19
34
  end
20
35
 
36
+ # Translate text to the to locale
37
+ # @param text the text to translate
38
+ # @param to the locale to translate to
39
+ # @return [String] the translated text or an error message
21
40
  def translate(text, to)
22
41
  EasyTranslate.translate(
23
42
  text,
@@ -25,8 +44,11 @@ module Glossync
25
44
  to: to,
26
45
  key: @api_key
27
46
  )
47
+ rescue SocketError
48
+ "failed to connect to google translate api"
28
49
  end
29
50
 
51
+ # :nodoc:
30
52
  def handle(_, who, field, locale)
31
53
  key = who.tl_key(field)
32
54
 
@@ -1,3 +1,3 @@
1
1
  module Glossync
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
data/lib/glossync.rb CHANGED
@@ -107,7 +107,7 @@ module Glossync
107
107
 
108
108
  # Call I18n.translate for the key corresponding to field
109
109
  #
110
- # @example QuizAnswer.first.tl_key(:answer) => "True"
110
+ # @example QuizAnswer.first.tl(:answer) => "True"
111
111
  #
112
112
  # @param field the field to translate
113
113
  # @return [String] the translated string
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glossync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stone Tickle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-08 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler