onesky-rails 1.0.0 → 1.1.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 +6 -0
- data/lib/onesky/rails/client.rb +1 -1
- data/lib/onesky/rails/file_client.rb +6 -10
- data/lib/onesky/rails/version.rb +1 -1
- data/lib/tasks/onesky.rake +3 -1
- data/onesky-rails.gemspec +1 -0
- data/spec/fixtures/locales/special_en.yml +2 -0
- data/spec/onesky/rails/client_spec.rb +12 -0
- data/spec/onesky/rails/file_client_spec.rb +26 -15
- data/spec/spec_helper.rb +2 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efdecfa76c426d6b3c7ba6f9312f98c914f2d2e5
|
4
|
+
data.tar.gz: 16d9375f705ad4266a060273adf35c724cde0ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cad9660e157d30d332a0a24b9a934696ef771c4e6a7d15698b37986a458876d4f7d2f22c7c5f93dd10736a201ace9097c4cdaa2c686cc8d0d73e450c6f25765
|
7
|
+
data.tar.gz: d423d3944b8ddef1b687f9bd7de0ec06e8bdea16ffd445a24c42f7fd237a9e004c474b063a278b9e7a72585aca993e064b00aefd0e17d70b17856cb9b6de27c0
|
data/CHANGELOG.md
CHANGED
data/lib/onesky/rails/client.rb
CHANGED
@@ -15,7 +15,7 @@ module Onesky
|
|
15
15
|
@client = ::Onesky::Client.new(@config['api_key'], @config['api_secret'])
|
16
16
|
@client.plugin_code = 'rails-string'
|
17
17
|
@project = @client.project(@config['project_id'].to_i)
|
18
|
-
@base_locale = ::I18n.default_locale
|
18
|
+
@base_locale = config_hash.fetch('base_locale', ::I18n.default_locale)
|
19
19
|
@onesky_locales = []
|
20
20
|
end
|
21
21
|
|
@@ -52,21 +52,16 @@ NOTICE
|
|
52
52
|
DIR_PREFIX + locale
|
53
53
|
end
|
54
54
|
|
55
|
-
def extract_file_name(header_hash)
|
56
|
-
search_text = 'filename='
|
57
|
-
if disposition = header_hash[:content_disposition]
|
58
|
-
if idx = disposition.index(search_text)
|
59
|
-
disposition[(idx + search_text.length)..-1]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
55
|
def make_translation_dir(dir_path, locale)
|
65
56
|
target_path = File.join(dir_path, locale_dir(locale))
|
66
57
|
Dir.mkdir(target_path) unless File.directory?(target_path)
|
67
58
|
target_path
|
68
59
|
end
|
69
60
|
|
61
|
+
def locale_file_name(file, to_locale)
|
62
|
+
file.sub(@base_locale.to_s, to_locale)
|
63
|
+
end
|
64
|
+
|
70
65
|
def get_default_locale_files(string_path)
|
71
66
|
Dir.glob("#{string_path}/**/*.yml").map do |path|
|
72
67
|
content_hash = YAML.load_file(path)
|
@@ -76,7 +71,8 @@ NOTICE
|
|
76
71
|
|
77
72
|
def save_translation(response, string_path, locale, file)
|
78
73
|
locale_path = make_translation_dir(string_path, locale)
|
79
|
-
target_file =
|
74
|
+
target_file = locale_file_name(file, locale)
|
75
|
+
|
80
76
|
File.open(File.join(locale_path, target_file), 'w') do |f|
|
81
77
|
f.write(TRANSLATION_NOTICE + response.body.force_encoding(ENCODING))
|
82
78
|
end
|
data/lib/onesky/rails/version.rb
CHANGED
data/lib/tasks/onesky.rake
CHANGED
@@ -13,7 +13,9 @@ namespace :onesky do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def file_client
|
16
|
-
|
16
|
+
require 'erb'
|
17
|
+
data = YAML::load(ERB.new(File.read(Rails.root.join('config', 'onesky.yml'))).result)
|
18
|
+
Onesky::Rails::FileClient.new data
|
17
19
|
end
|
18
20
|
|
19
21
|
def locale_path
|
data/onesky-rails.gemspec
CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.3"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.1.0"
|
27
|
+
spec.add_development_dependency "timecop", "~> 0.7.0"
|
27
28
|
spec.add_development_dependency "webmock", "~> 1.19.0"
|
28
29
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Onesky::Rails::Client do
|
4
|
+
let(:config_hash) { create_config_hash }
|
4
5
|
|
5
6
|
describe '#new' do
|
6
7
|
|
@@ -31,6 +32,17 @@ describe Onesky::Rails::Client do
|
|
31
32
|
expect{client.verify_languages!}.to_not raise_error
|
32
33
|
expect(client.onesky_locales).to eq(['ja'])
|
33
34
|
end
|
35
|
+
|
36
|
+
context 'with explicit base locale and different default locale' do
|
37
|
+
let(:config_hash) { create_config_hash.merge({'base_locale' => 'en'}) }
|
38
|
+
|
39
|
+
it 'to retrieve languages activated at OneSky' do
|
40
|
+
I18n.default_locale = :ja
|
41
|
+
|
42
|
+
expect{client.verify_languages!}.to_not raise_error
|
43
|
+
expect(client.onesky_locales).to eq(['ja'])
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
context 'fail' do
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Onesky::Rails::FileClient do
|
4
4
|
|
5
|
+
let(:config_hash) { create_config_hash }
|
5
6
|
let(:client) {Onesky::Rails::FileClient.new(config_hash)}
|
6
7
|
let(:file_path) { File.expand_path("../../../fixtures/locales", __FILE__) }
|
7
8
|
|
@@ -10,24 +11,21 @@ describe Onesky::Rails::FileClient do
|
|
10
11
|
end
|
11
12
|
|
12
13
|
context '#upload' do
|
13
|
-
it '
|
14
|
+
it 'all translation files to onesky' do
|
14
15
|
stub_request(:post, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/files", config_hash['api_key'], config_hash['api_secret']))
|
15
16
|
.to_return(status: 201)
|
16
17
|
|
17
|
-
expect(client.upload(file_path)).to
|
18
|
+
expect(client.upload(file_path)).to match_array(["#{file_path}/en.yml","#{file_path}/special_en.yml"])
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
context 'download' do
|
22
23
|
|
23
|
-
let(:
|
24
|
-
|
25
|
-
{
|
26
|
-
'Content-Type' => 'text/plain',
|
27
|
-
'Content-Disposition' => "attachment; filename=#{file_name}",
|
28
|
-
}
|
24
|
+
let(:expected_locale_files) do
|
25
|
+
["#{locale_dir}/ja.yml", "#{locale_dir}/special_ja.yml"]
|
29
26
|
end
|
30
|
-
|
27
|
+
|
28
|
+
let(:file_names) {['en.yml', 'special_en.yml']}
|
31
29
|
|
32
30
|
def locale_dir
|
33
31
|
File.join(file_path, 'onesky_ja')
|
@@ -53,16 +51,29 @@ describe Onesky::Rails::FileClient do
|
|
53
51
|
end
|
54
52
|
|
55
53
|
it 'download translations from OneSky and save as YAML files' do
|
56
|
-
|
57
|
-
.to_return(
|
58
|
-
status: 200,
|
59
|
-
body: File.read(File.join(file_path, file_name)),
|
60
|
-
headers: response_headers)
|
54
|
+
prepare_download_requests!
|
61
55
|
|
62
56
|
expect(locale_files).to be_empty
|
63
57
|
client.download(file_path)
|
64
|
-
expect(locale_files).to
|
58
|
+
expect(locale_files).to match_array(expected_locale_files)
|
65
59
|
end
|
60
|
+
|
61
|
+
def prepare_download_requests!
|
62
|
+
Timecop.freeze
|
63
|
+
file_names.each do |file_name|
|
64
|
+
response_headers = {
|
65
|
+
'Content-Type' => 'text/plain',
|
66
|
+
'Content-Disposition' => "attachment; filename=#{file_name}",
|
67
|
+
}
|
68
|
+
query_string = "&source_file_name=#{file_name}&locale=ja"
|
69
|
+
stub_request(:get, full_path_with_auth_hash("/projects/#{config_hash['project_id']}/translations", config_hash['api_key'], config_hash['api_secret']) + query_string)
|
70
|
+
.to_return(
|
71
|
+
status: 200,
|
72
|
+
body: File.read(File.join(file_path, file_name)),
|
73
|
+
headers: response_headers)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
66
77
|
end
|
67
78
|
|
68
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,7 @@ require 'webmock/rspec'
|
|
3
3
|
require 'i18n'
|
4
4
|
require 'onesky/rails'
|
5
5
|
require 'onesky'
|
6
|
+
require 'timecop'
|
6
7
|
|
7
8
|
WebMock.disable_net_connect!(allow_localhost: true)
|
8
9
|
|
@@ -46,7 +47,7 @@ def languages_response
|
|
46
47
|
}
|
47
48
|
end
|
48
49
|
|
49
|
-
def
|
50
|
+
def create_config_hash
|
50
51
|
{
|
51
52
|
"api_key" => 'fakeapi',
|
52
53
|
"api_secret" => 'fakesecret',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onesky-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Lam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.7.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.7.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: webmock
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,7 @@ files:
|
|
122
136
|
- spec/fixtures/locales/en.json
|
123
137
|
- spec/fixtures/locales/en.yml
|
124
138
|
- spec/fixtures/locales/ja.yml
|
139
|
+
- spec/fixtures/locales/special_en.yml
|
125
140
|
- spec/onesky/rails/client_spec.rb
|
126
141
|
- spec/onesky/rails/file_client_spec.rb
|
127
142
|
- spec/spec_helper.rb
|
@@ -153,7 +168,7 @@ test_files:
|
|
153
168
|
- spec/fixtures/locales/en.json
|
154
169
|
- spec/fixtures/locales/en.yml
|
155
170
|
- spec/fixtures/locales/ja.yml
|
171
|
+
- spec/fixtures/locales/special_en.yml
|
156
172
|
- spec/onesky/rails/client_spec.rb
|
157
173
|
- spec/onesky/rails/file_client_spec.rb
|
158
174
|
- spec/spec_helper.rb
|
159
|
-
has_rdoc:
|