onesky-rails 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +5 -0
- data/README.md +14 -2
- data/lib/onesky/rails/file_client.rb +22 -2
- data/lib/onesky/rails/version.rb +1 -1
- data/lib/tasks/onesky.rake +15 -3
- data/spec/fixtures/sample_files/en/en.yml +13 -0
- data/spec/fixtures/sample_files/en/special_en.yml +3 -0
- data/spec/fixtures/{locales → sample_files/ja}/ja.yml +4 -0
- data/spec/fixtures/sample_files/ja/special_ja.yml +3 -0
- data/spec/fixtures/{locales → sample_files/original}/en.yml +0 -0
- data/spec/fixtures/{locales → sample_files/original}/special_en.yml +0 -0
- data/spec/onesky/rails/file_client_spec.rb +56 -26
- metadata +14 -10
- data/spec/fixtures/locales/en.json +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c39b314d8923cbeb02de9aa079f5a7879b42d1cb
|
4
|
+
data.tar.gz: ca29ec9a0b41898afbc58f0bb361a610e8e1efc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2136ba483f9b8a6455039c8dc0da0a0649b4945ce9fff4434919e92d32d9f17a38f57ec83c075e10a26735035eb08765413336168f0289955105789a899bc352
|
7
|
+
data.tar.gz: 0d66f3beef5005099a61e561fcd4d6a3e90e0cab30f22f21f2402d766456f3099cd287f4ff690a180043dfcb2b9e60202ff390d6a8703580c25a7b40ed6d6f83
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -36,12 +36,24 @@ Upload all string files of `I18n.default_locale` to [OneSky](http://www.oneskyap
|
|
36
36
|
```
|
37
37
|
rake onesky:download
|
38
38
|
```
|
39
|
-
Download translations of files uploaded in all languages activated in project.
|
39
|
+
Download translations of files uploaded in all languages activated in project other than the base language.
|
40
|
+
|
41
|
+
**Download base language translations**
|
42
|
+
```
|
43
|
+
rake onesky:download_base
|
44
|
+
```
|
45
|
+
Download translations of files uploaded only for the base language.
|
46
|
+
|
47
|
+
**Download all languages translations**
|
48
|
+
```
|
49
|
+
rake onesky:download_all
|
50
|
+
```
|
51
|
+
Download translations of files uploaded for all the languages including the base language.
|
40
52
|
|
41
53
|
## TODO
|
42
54
|
- Specify file to upload
|
43
55
|
- Specify file and language to download
|
44
|
-
- Support
|
56
|
+
- Support different backend
|
45
57
|
|
46
58
|
## Contributing
|
47
59
|
|
@@ -28,12 +28,30 @@ NOTICE
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
##
|
32
|
+
# Download translations from OneSky platform
|
33
|
+
#
|
34
|
+
# +string_path+ specify the folder path where all localization files locate
|
35
|
+
# +options+ indicate which files to download
|
36
|
+
# - :base_only => base language only
|
37
|
+
# - :all => all languages including base language
|
38
|
+
# - <empty> => default value; translation languages
|
39
|
+
#
|
40
|
+
def download(string_path, options = {})
|
32
41
|
verify_languages!
|
33
42
|
|
34
43
|
files = get_default_locale_files(string_path).map {|path| File.basename(path)}
|
35
44
|
|
36
|
-
|
45
|
+
locales = if options[:base_only]
|
46
|
+
[@base_locale]
|
47
|
+
elsif options[:all]
|
48
|
+
[@base_locale] + @onesky_locales
|
49
|
+
else
|
50
|
+
@onesky_locales
|
51
|
+
end
|
52
|
+
|
53
|
+
locales.each do |locale|
|
54
|
+
locale = locale.to_s
|
37
55
|
puts "#{locale_dir(locale)}/"
|
38
56
|
onesky_locale = locale.gsub('_', '-')
|
39
57
|
files.each do |file|
|
@@ -53,6 +71,8 @@ NOTICE
|
|
53
71
|
end
|
54
72
|
|
55
73
|
def make_translation_dir(dir_path, locale)
|
74
|
+
return dir_path if locale == @base_locale.to_s
|
75
|
+
|
56
76
|
target_path = File.join(dir_path, locale_dir(locale))
|
57
77
|
Dir.mkdir(target_path) unless File.directory?(target_path)
|
58
78
|
target_path
|
data/lib/onesky/rails/version.rb
CHANGED
data/lib/tasks/onesky.rake
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
namespace :onesky do
|
2
2
|
|
3
|
-
desc
|
3
|
+
desc 'Upload string files of base locale to OneSky platform.'
|
4
4
|
task :upload => :environment do
|
5
5
|
file_client.upload(locale_path)
|
6
6
|
puts 'Done!'
|
7
7
|
end
|
8
8
|
|
9
|
-
desc
|
9
|
+
desc 'Download translations from OneSky platform.'
|
10
10
|
task :download => :environment do
|
11
11
|
file_client.download(locale_path)
|
12
12
|
puts 'Done!'
|
13
13
|
end
|
14
14
|
|
15
|
+
desc 'Download base language translations from OneSky platform.'
|
16
|
+
task :download_base => :environment do
|
17
|
+
file_client.download(locale_path, base_only: true)
|
18
|
+
puts 'Done!'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Download all languages translations from OneSky platform.'
|
22
|
+
task :download_all => :environment do
|
23
|
+
file_client.download(locale_path, all: true)
|
24
|
+
puts 'Done!'
|
25
|
+
end
|
26
|
+
|
15
27
|
def file_client
|
16
28
|
require 'erb'
|
17
29
|
data = YAML::load(ERB.new(File.read(Rails.root.join('config', 'onesky.yml'))).result)
|
@@ -19,7 +31,7 @@ namespace :onesky do
|
|
19
31
|
end
|
20
32
|
|
21
33
|
def locale_path
|
22
|
-
Rails.root.join(
|
34
|
+
Rails.root.join('config/locales')
|
23
35
|
end
|
24
36
|
|
25
37
|
end
|
File without changes
|
File without changes
|
@@ -4,10 +4,19 @@ describe Onesky::Rails::FileClient do
|
|
4
4
|
|
5
5
|
let(:config_hash) { create_config_hash }
|
6
6
|
let(:client) {Onesky::Rails::FileClient.new(config_hash)}
|
7
|
+
let(:sample_file_path) { File.expand_path("../../../fixtures/sample_files", __FILE__) }
|
7
8
|
let(:file_path) { File.expand_path("../../../fixtures/locales", __FILE__) }
|
8
9
|
|
9
10
|
before(:each) do
|
10
11
|
stub_language_request(config_hash['api_key'], config_hash['api_secret'], config_hash['project_id'])
|
12
|
+
|
13
|
+
# create test dir
|
14
|
+
FileUtils.copy_entry "#{sample_file_path}/original", file_path
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
# delete test dir
|
19
|
+
FileUtils.remove_dir(file_path) if File.directory?(file_path)
|
11
20
|
end
|
12
21
|
|
13
22
|
context '#upload' do
|
@@ -21,55 +30,76 @@ describe Onesky::Rails::FileClient do
|
|
21
30
|
|
22
31
|
context 'download' do
|
23
32
|
|
24
|
-
let(:expected_locale_files) do
|
25
|
-
["#{locale_dir}/ja.yml", "#{locale_dir}/special_ja.yml"]
|
26
|
-
end
|
27
|
-
|
28
33
|
let(:file_names) {['en.yml', 'special_en.yml']}
|
29
34
|
|
30
|
-
def locale_dir
|
31
|
-
File.join(file_path, 'onesky_ja')
|
35
|
+
def locale_dir(locale)
|
36
|
+
locale == I18n.default_locale.to_s ? file_path : File.join(file_path, 'onesky_ja')
|
32
37
|
end
|
33
38
|
|
34
|
-
def locale_files
|
35
|
-
Dir.glob("#{locale_dir}/*.yml")
|
39
|
+
def locale_files(locale)
|
40
|
+
Dir.glob("#{locale_dir(locale)}/*.yml")
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
39
|
-
|
40
|
-
File.delete(*Dir.glob("#{locale_dir}/**/*"))
|
41
|
-
Dir.delete(locale_dir)
|
42
|
-
end
|
43
|
+
def expected_locale_files(locale)
|
44
|
+
["#{locale_dir(locale)}/#{locale}.yml", "#{locale_dir(locale)}/special_#{locale}.yml"]
|
43
45
|
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
+
it 'download translations from OneSky and save as YAML files' do
|
48
|
+
locale = 'ja'
|
49
|
+
prepare_download_requests!(locale)
|
50
|
+
|
51
|
+
expect(locale_files(locale)).to be_empty
|
52
|
+
client.download(file_path)
|
53
|
+
expect(locale_files(locale)).to match_array(expected_locale_files(locale))
|
47
54
|
end
|
48
55
|
|
49
|
-
|
50
|
-
|
56
|
+
it 'download translations of base language from OneSky' do
|
57
|
+
locale = 'en'
|
58
|
+
prepare_download_requests!(locale)
|
59
|
+
|
60
|
+
client.download(file_path, base_only: true)
|
61
|
+
|
62
|
+
# test files created
|
63
|
+
expected_files = expected_locale_files(locale)
|
64
|
+
expect(locale_files(locale)).to match_array(expected_files)
|
65
|
+
|
66
|
+
# test file content
|
67
|
+
content = YAML.load_file(expected_files.pop)
|
68
|
+
expected_content = YAML.load_file(File.join(sample_file_path, locale, 'special_en.yml'))
|
69
|
+
expect(content).to eq(expected_content)
|
51
70
|
end
|
52
71
|
|
53
|
-
it 'download translations
|
54
|
-
|
72
|
+
it 'download all translations including base language from OneSky' do
|
73
|
+
locales = ['en', 'ja']
|
74
|
+
locales.each { |locale| prepare_download_requests!(locale) }
|
55
75
|
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
client.download(file_path, all: true)
|
77
|
+
|
78
|
+
locales.each do |locale|
|
79
|
+
# test files created
|
80
|
+
expected_files = expected_locale_files(locale)
|
81
|
+
expect(locale_files(locale)).to match_array(expected_files)
|
82
|
+
|
83
|
+
# test file content
|
84
|
+
content = YAML.load_file(expected_files.pop)
|
85
|
+
expected_content = YAML.load_file(File.join(sample_file_path, locale, "special_#{locale}.yml"))
|
86
|
+
expect(content).to eq(expected_content)
|
87
|
+
end
|
59
88
|
end
|
60
89
|
|
61
|
-
def prepare_download_requests!
|
90
|
+
def prepare_download_requests!(locale)
|
62
91
|
Timecop.freeze
|
63
92
|
file_names.each do |file_name|
|
93
|
+
downloaded_file_name = file_name.sub(/en/, locale)
|
64
94
|
response_headers = {
|
65
95
|
'Content-Type' => 'text/plain',
|
66
|
-
'Content-Disposition' => "attachment; filename=#{
|
96
|
+
'Content-Disposition' => "attachment; filename=#{downloaded_file_name}",
|
67
97
|
}
|
68
|
-
query_string = "&source_file_name=#{file_name}&locale
|
98
|
+
query_string = "&source_file_name=#{file_name}&locale=#{locale}"
|
69
99
|
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
100
|
.to_return(
|
71
101
|
status: 200,
|
72
|
-
body: File.read(File.join(
|
102
|
+
body: File.read(File.join(sample_file_path, locale, downloaded_file_name)),
|
73
103
|
headers: response_headers)
|
74
104
|
end
|
75
105
|
end
|
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.3.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: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -133,10 +133,12 @@ files:
|
|
133
133
|
- lib/onesky/rails/version.rb
|
134
134
|
- lib/tasks/onesky.rake
|
135
135
|
- onesky-rails.gemspec
|
136
|
-
- spec/fixtures/
|
137
|
-
- spec/fixtures/
|
138
|
-
- spec/fixtures/
|
139
|
-
- spec/fixtures/
|
136
|
+
- spec/fixtures/sample_files/en/en.yml
|
137
|
+
- spec/fixtures/sample_files/en/special_en.yml
|
138
|
+
- spec/fixtures/sample_files/ja/ja.yml
|
139
|
+
- spec/fixtures/sample_files/ja/special_ja.yml
|
140
|
+
- spec/fixtures/sample_files/original/en.yml
|
141
|
+
- spec/fixtures/sample_files/original/special_en.yml
|
140
142
|
- spec/onesky/rails/client_spec.rb
|
141
143
|
- spec/onesky/rails/file_client_spec.rb
|
142
144
|
- spec/spec_helper.rb
|
@@ -165,10 +167,12 @@ signing_key:
|
|
165
167
|
specification_version: 4
|
166
168
|
summary: Rails plugin to sync string files with OneSky
|
167
169
|
test_files:
|
168
|
-
- spec/fixtures/
|
169
|
-
- spec/fixtures/
|
170
|
-
- spec/fixtures/
|
171
|
-
- spec/fixtures/
|
170
|
+
- spec/fixtures/sample_files/en/en.yml
|
171
|
+
- spec/fixtures/sample_files/en/special_en.yml
|
172
|
+
- spec/fixtures/sample_files/ja/ja.yml
|
173
|
+
- spec/fixtures/sample_files/ja/special_ja.yml
|
174
|
+
- spec/fixtures/sample_files/original/en.yml
|
175
|
+
- spec/fixtures/sample_files/original/special_en.yml
|
172
176
|
- spec/onesky/rails/client_spec.rb
|
173
177
|
- spec/onesky/rails/file_client_spec.rb
|
174
178
|
- spec/spec_helper.rb
|