copy_tuner_client 0.7.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +2 -1
- data/copy_tuner_client.gemspec +1 -0
- data/lib/copy_tuner_client/configuration.rb +1 -1
- data/lib/copy_tuner_client/copyray_middleware.rb +12 -6
- data/lib/copy_tuner_client/i18n_backend.rb +4 -0
- data/lib/copy_tuner_client/i18n_compat.rb +14 -0
- data/lib/copy_tuner_client/translation_log.rb +1 -1
- data/lib/copy_tuner_client/version.rb +1 -1
- data/lib/tasks/copy_tuner_client_tasks.rake +15 -2
- data/spec/copy_tuner_client/i18n_backend_spec.rb +7 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bccd14def1ebe5752df2720935cff2474e749adc498cdcd310e4c8eeb3144245
|
4
|
+
data.tar.gz: f1acb0047c41797eb773eb852379d1921e040a1e5688eea89a7becce3f4540c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 669c8e6bc71974318d16f4277f498a8933869486a23a9fcbbd67375cfd9d8325e65a700645b01454d062d986763a32a264f33d3b01f2ec41cc7e4d5d5fe7035d
|
7
|
+
data.tar.gz: b201841f91363ec9f725bd071f2ddb8f341412ba0ce58edcd9e39b530ff092356592d33a57366fed95070d64e0226b428144b4fc315ffc6b121ac062f6d2848f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.10.0
|
2
|
+
|
3
|
+
- Add copy_tuner:detect_html_incompatible_keys task
|
4
|
+
|
5
|
+
## 0.9.0
|
6
|
+
|
7
|
+
- Do not upload invalid type keys
|
8
|
+
|
9
|
+
## 0.8.1
|
10
|
+
|
11
|
+
- Fix bug in `CopyrayMiddleware`
|
12
|
+
|
13
|
+
## 0.8.0
|
14
|
+
|
15
|
+
- Change the default value of config.upload_disabled_environments
|
16
|
+
|
1
17
|
## 0.7.0
|
2
18
|
|
3
19
|
- Add config.upload_disabled_environments
|
data/Gemfile.lock
CHANGED
data/copy_tuner_client.gemspec
CHANGED
@@ -6,6 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.required_ruby_version = '>= 2.5.0'
|
7
7
|
s.add_dependency 'i18n', '>= 0.5.0'
|
8
8
|
s.add_dependency 'json'
|
9
|
+
s.add_dependency 'nokogiri'
|
9
10
|
s.add_development_dependency 'rails', '~> 5.2.4.2'
|
10
11
|
s.add_development_dependency 'rake'
|
11
12
|
s.add_development_dependency 'rspec', '3.8.0' # NOTE: 3.9.0だとundefined method `synchronize'でコケるテストがある
|
@@ -148,7 +148,7 @@ module CopyTunerClient
|
|
148
148
|
self.sync_interval_staging = 0
|
149
149
|
self.secure = true
|
150
150
|
self.test_environments = %w(test cucumber)
|
151
|
-
self.upload_disabled_environments = []
|
151
|
+
self.upload_disabled_environments = %w[production staging]
|
152
152
|
self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com'
|
153
153
|
self.disable_copyray_comment_injection = false
|
154
154
|
self.html_escape = false
|
@@ -37,14 +37,14 @@ module CopyTunerClient
|
|
37
37
|
if CopyTunerClient::TranslationLog.initialized?
|
38
38
|
json = CopyTunerClient::TranslationLog.translations.to_json
|
39
39
|
# Use block to avoid back reference \?
|
40
|
-
html
|
40
|
+
append_to_html_body(html, "<div id='copy-tuner-data' data-copy-tuner-translation-log='#{ERB::Util.html_escape json}' data-copy-tuner-url='#{CopyTunerClient.configuration.project_url}'></div>")
|
41
41
|
else
|
42
42
|
html
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def inject_copy_tuner_bar(html)
|
47
|
-
html
|
47
|
+
append_to_html_body(html, render_copy_tuner_bar)
|
48
48
|
end
|
49
49
|
|
50
50
|
def render_copy_tuner_bar
|
@@ -59,19 +59,25 @@ module CopyTunerClient
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def append_css(html)
|
62
|
-
html
|
62
|
+
append_to_html_body(html, css_tag)
|
63
63
|
end
|
64
64
|
|
65
65
|
def append_js(html)
|
66
|
-
html.
|
67
|
-
"#{helpers.javascript_include_tag(:copyray)}\n#{Regexp.last_match}"
|
68
|
-
end
|
66
|
+
append_to_html_body(html, helpers.javascript_include_tag(:copyray))
|
69
67
|
end
|
70
68
|
|
71
69
|
def css_tag
|
72
70
|
helpers.stylesheet_link_tag :copyray, media: :all
|
73
71
|
end
|
74
72
|
|
73
|
+
def append_to_html_body(html, content)
|
74
|
+
content = content.html_safe if content.respond_to?(:html_safe)
|
75
|
+
return html unless html.include?('</body>')
|
76
|
+
|
77
|
+
position = html.rindex('</body>')
|
78
|
+
html.insert(position, content + "\n")
|
79
|
+
end
|
80
|
+
|
75
81
|
def file?(headers)
|
76
82
|
headers["Content-Transfer-Encoding"] == "binary"
|
77
83
|
end
|
@@ -61,6 +61,8 @@ module CopyTunerClient
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def lookup(locale, key, scope = [], options = {})
|
64
|
+
return nil if !key.is_a?(String) && !key.is_a?(Symbol)
|
65
|
+
|
64
66
|
parts = I18n.normalize_keys(locale, key, scope, options[:separator])
|
65
67
|
key_with_locale = parts.join('.')
|
66
68
|
content = cache[key_with_locale] || super
|
@@ -86,6 +88,8 @@ module CopyTunerClient
|
|
86
88
|
|
87
89
|
def default(locale, object, subject, options = {})
|
88
90
|
content = super(locale, object, subject, options)
|
91
|
+
return content if !object.is_a?(String) && !object.is_a?(Symbol)
|
92
|
+
|
89
93
|
if content.respond_to?(:to_str)
|
90
94
|
parts = I18n.normalize_keys(locale, object, options[:scope], options[:separator])
|
91
95
|
# NOTE: ActionView::Helpers::TranslationHelper#translate wraps default String in an Array
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module CopyTunerClient
|
4
|
+
module I18nCompat
|
5
|
+
def select_html_incompatible_blurbs(blurbs)
|
6
|
+
non_html_key_blurbs = blurbs.reject { |key| key.ends_with?('.html') || key.ends_with?('_html') }
|
7
|
+
html_blurbs = non_html_key_blurbs.select do |key, content|
|
8
|
+
Nokogiri::HTML.fragment(content).children.any? { |node| node.name != 'text' }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module_function :select_html_incompatible_blurbs
|
13
|
+
end
|
14
|
+
end
|
@@ -19,7 +19,7 @@ module CopyTunerClient
|
|
19
19
|
def self.install_hook
|
20
20
|
I18n.class_eval do
|
21
21
|
class << self
|
22
|
-
def translate_with_copy_tuner_hook(key, **options)
|
22
|
+
def translate_with_copy_tuner_hook(key = nil, **options)
|
23
23
|
scope = options[:scope]
|
24
24
|
scope = scope.dup if scope.is_a?(Array) || scope.is_a?(String)
|
25
25
|
result = translate_without_copy_tuner_hook(key, **options)
|
@@ -25,8 +25,21 @@ namespace :copy_tuner do
|
|
25
25
|
if conflict_keys.empty?
|
26
26
|
puts 'All success'
|
27
27
|
else
|
28
|
-
|
29
|
-
|
28
|
+
puts conflict_keys.sort.join("\n")
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Detect html incompatible keys."
|
34
|
+
task :detect_html_incompatible_keys => :environment do
|
35
|
+
require 'copy_tuner_client/i18n_compat'
|
36
|
+
html_incompatible_blurbs = CopyTunerClient::I18nCompat.select_html_incompatible_blurbs(CopyTunerClient.cache.blurbs)
|
37
|
+
|
38
|
+
if html_incompatible_blurbs.empty?
|
39
|
+
puts 'All success'
|
40
|
+
else
|
41
|
+
puts html_incompatible_blurbs.keys.sort.join("\n")
|
42
|
+
exit 1
|
30
43
|
end
|
31
44
|
end
|
32
45
|
end
|
@@ -139,6 +139,13 @@ describe CopyTunerClient::I18nBackend do
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
context 'non-string key' do
|
143
|
+
it 'Not to be registered in the cache' do
|
144
|
+
expect { subject.translate('en', {}) }.to throw_symbol(:exception)
|
145
|
+
expect(cache).not_to have_key 'en.{}'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
142
149
|
describe "with stored translations" do
|
143
150
|
subject { build_backend }
|
144
151
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_tuner_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SonicGarden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +212,7 @@ files:
|
|
198
212
|
- lib/copy_tuner_client/engine.rb
|
199
213
|
- lib/copy_tuner_client/errors.rb
|
200
214
|
- lib/copy_tuner_client/i18n_backend.rb
|
215
|
+
- lib/copy_tuner_client/i18n_compat.rb
|
201
216
|
- lib/copy_tuner_client/poller.rb
|
202
217
|
- lib/copy_tuner_client/prefixed_logger.rb
|
203
218
|
- lib/copy_tuner_client/process_guard.rb
|