voltron-translate 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +5 -1
- data/lib/voltron/translatable.rb +2 -2
- data/lib/voltron/translate.rb +7 -4
- data/lib/voltron/translate/version.rb +1 -1
- data/voltron-translate.gemspec +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d63716690236d33ce9d8497b2e4e84c7ee9355a3
|
4
|
+
data.tar.gz: 6d4fef31cd140a923b02ca508169b5470aab9612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e357d22054599503b00a94deaf3a9e065e21f574f26e3fe2dabf8c585339ed235647816c4981d066815c41ddd02f50bed672555faf429f8e31601ab57dd8726
|
7
|
+
data.tar.gz: 3a8b8c93887fba7de22eed4b4e70e11989b7cd689f861767bc3a25783bd71eb12c913d71ef4c08909fe6cea58e04ed9f08f1c74e828a0674e0c196c2a180ebc0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Voltron Translate is a different, in my mind more logical way of dealing with in
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
gem 'voltron-translate', '~> 0.2.
|
14
|
+
gem 'voltron-translate', '~> 0.2.2'
|
15
15
|
```
|
16
16
|
|
17
17
|
And then execute:
|
@@ -201,6 +201,10 @@ Should go without saying, but to set the translation text on the frontend, you'd
|
|
201
201
|
|
202
202
|
Add the appropriate attributes to your strong params, so on, so on...
|
203
203
|
|
204
|
+
## Caching
|
205
|
+
|
206
|
+
This gem relies on being able to cache translations for quicker lookup. While not a requirement, some sort of cache mechanism is highly recommended as you will notice a difference in page load time. Using [redis-rails](https://github.com/redis-store/redis-rails) or something similar is the most preferred method of caching, but even [FileStore](http://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-filestore) is better than nothing.
|
207
|
+
|
204
208
|
## Note
|
205
209
|
|
206
210
|
Setting `Voltron.config.translate.enabled` to `false` will never break any `__()` call, it simply causes it to ignore the locale argument (if specified) and return the interpolated string using the latter arguments (again, if any)
|
data/lib/voltron/translatable.rb
CHANGED
@@ -5,7 +5,7 @@ module Voltron
|
|
5
5
|
include InstanceMethods
|
6
6
|
|
7
7
|
options = (attributes.extract_options!).with_indifferent_access
|
8
|
-
locales = Array.wrap(options[:locales] || Voltron.config.translate.locales).map
|
8
|
+
locales = Array.wrap(options[:locales] || Voltron.config.translate.locales).map { |l| l.to_s.underscore }
|
9
9
|
|
10
10
|
attributes.each do |attrib|
|
11
11
|
|
@@ -20,7 +20,7 @@ module Voltron
|
|
20
20
|
# locale specified for the attribute, and ultimately the current locale translation
|
21
21
|
# If still nil, returns the value from super
|
22
22
|
define_method :"#{attrib}" do |locale=nil|
|
23
|
-
# +action_view/helpers/
|
23
|
+
# +action_view/helpers/tags+ exist when this method is called from within
|
24
24
|
# ActionView::Helpers. In other words, form helper tags. In that
|
25
25
|
# case we want the actual value of the attribute, not whatever the locale is
|
26
26
|
return super() if caller.any? { |l| /action_view\/helpers\/tags/.match(l) } || !Voltron.config.translate.enabled?
|
data/lib/voltron/translate.rb
CHANGED
@@ -5,10 +5,13 @@ require 'voltron/translatable'
|
|
5
5
|
require 'digest'
|
6
6
|
require 'csv'
|
7
7
|
require 'google_hash'
|
8
|
+
require 'xxhash'
|
8
9
|
|
9
10
|
module Voltron
|
10
11
|
module Translate
|
11
12
|
|
13
|
+
LOG_COLOR = :light_blue
|
14
|
+
|
12
15
|
class InvalidColumnTypeError < StandardError; end
|
13
16
|
|
14
17
|
def __(text, locale = I18n.locale, **args)
|
@@ -19,14 +22,14 @@ module Voltron
|
|
19
22
|
|
20
23
|
# If app is running in one of the environments where translations can be created
|
21
24
|
if Voltron.config.translate.buildable?
|
22
|
-
Voltron.config.translate.locales.each { |locale| translator(locale).write text }
|
25
|
+
Array.wrap(Voltron.config.translate.locales).compact.each { |locale| translator(locale).write text }
|
23
26
|
end
|
24
27
|
|
25
28
|
# Translate the text and return it
|
26
29
|
translator(locale).translate text, **args
|
27
30
|
rescue => e
|
28
31
|
# If any errors occurred, log the error and just return the default interpolated text
|
29
|
-
Voltron.log e.message.to_s + " (Original Translation Text: #{text})", 'Translate',
|
32
|
+
Voltron.log e.message.to_s + " (Original Translation Text: #{text})", 'Translate', ::Voltron::Translate::LOG_COLOR
|
30
33
|
text % args
|
31
34
|
end
|
32
35
|
end
|
@@ -61,7 +64,7 @@ module Voltron
|
|
61
64
|
# If the full list of translations does not contain the given text content, add it
|
62
65
|
unless full_list.has_key?(text)
|
63
66
|
CSV.open(path, 'a', force_quotes: true) { |f| f.puts [text, text] }
|
64
|
-
Voltron.log "Added translation for text '#{text}' (Locale: #{locale})", 'Translate',
|
67
|
+
Voltron.log "Added translation for text '#{text}' (Locale: #{locale})", 'Translate', ::Voltron::Translate::LOG_COLOR
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
@@ -139,7 +142,7 @@ module Voltron
|
|
139
142
|
end
|
140
143
|
|
141
144
|
def phrase_key(text, args)
|
142
|
-
key =
|
145
|
+
key = XXhash.xxh32(text + args.map { |k,v| "#{k}#{v}" }.join)
|
143
146
|
"translations/phrase/#{key}/#{locale}/#{modified}"
|
144
147
|
end
|
145
148
|
end
|
data/voltron-translate.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'rails', '>= 4.2'
|
22
22
|
spec.add_dependency 'voltron', '~> 0.2.4'
|
23
23
|
spec.add_dependency 'google_hash', '>= 0.9.0'
|
24
|
+
spec.add_dependency 'xxhash', '~> 0.4.0'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler', '>= 1.12'
|
26
27
|
spec.add_development_dependency 'rake', '>= 10.0'
|
@@ -29,5 +30,4 @@ Gem::Specification.new do |spec|
|
|
29
30
|
spec.add_development_dependency 'sqlite3', '>= 1.2'
|
30
31
|
spec.add_development_dependency 'simplecov', '0.11.0'
|
31
32
|
spec.add_development_dependency 'factory_girl_rails', '>= 4.7'
|
32
|
-
spec.add_development_dependency 'byebug'
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voltron-translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hainer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: xxhash
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.4.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.4.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +164,6 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '4.7'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: byebug
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
167
|
description:
|
168
168
|
email:
|
169
169
|
- eric@commercekitchen.com
|