glossync 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/glossync/config.rb +7 -2
- data/lib/glossync/exceptions.rb +2 -0
- data/lib/glossync/missing_translation_handler.rb +22 -0
- data/lib/glossync/version.rb +1 -1
- data/lib/glossync.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9691ad226bb7f81bec886d45d957fabb312707ed74c0c21bdb65a9a83273420
|
4
|
+
data.tar.gz: 16f7f0279a84bc2419df6426a8212c1c746bc097ff2fd748c31f9ae562517f10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b673baf2a80741bb0e9e7b8fd5ab270bbfc4007821a27a454f81d5fcdf0ed80886844afcf7453f3a8c1d0f57b3ec8d5c8ed8d8ae451a004bd0d578dd24e6b3d
|
7
|
+
data.tar.gz: 5654114e854ad28c2b7b5e6f6054dda4c27037d85ad5fdfa12360452bcaef5bd9442087cbf0321a11db98482a1de9af7691dff5280a5a59d69c54fff9b78feb3
|
data/lib/glossync/config.rb
CHANGED
@@ -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
|
data/lib/glossync/exceptions.rb
CHANGED
@@ -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
|
|
data/lib/glossync/version.rb
CHANGED
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.
|
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.
|
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-
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|