onesky-rails 1.2.0 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7310078e5234d06c2c9bf53aeaf4dc69c7460386
4
- data.tar.gz: 01d3730c16eb8b98cee057605eb73de3c73b2ba5
3
+ metadata.gz: c39b314d8923cbeb02de9aa079f5a7879b42d1cb
4
+ data.tar.gz: ca29ec9a0b41898afbc58f0bb361a610e8e1efc0
5
5
  SHA512:
6
- metadata.gz: 769551ebb66adc4badd7dbe197fa653142719a385d732cc89c4d7dd1afff2dd74a606176d6cf3a8701e55cc787b8f4db16fc11e4f980a6470d8b7730fb3f7e79
7
- data.tar.gz: 02f599857a3116ef72575bc84c7f54f02ae021e9e1afc0980d5ca5e574d4dd227de2ec141c391c5ac6844ac26425e4db5119707d4cd04bc1eb549d62197fa7d3
6
+ metadata.gz: 2136ba483f9b8a6455039c8dc0da0a0649b4945ce9fff4434919e92d32d9f17a38f57ec83c075e10a26735035eb08765413336168f0289955105789a899bc352
7
+ data.tar.gz: 0d66f3beef5005099a61e561fcd4d6a3e90e0cab30f22f21f2402d766456f3099cd287f4ff690a180043dfcb2b9e60202ff390d6a8703580c25a7b40ed6d6f83
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.1
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
@@ -18,3 +18,8 @@
18
18
  ### 1.2.0 - 13-JUL-2015
19
19
 
20
20
  * support custom locale
21
+
22
+ ### 1.3.0 - 13-MAY-2016
23
+
24
+ * support download base language only translation files
25
+ * support download all translation files
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 framework other than RoR
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
- def download(string_path)
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
- @onesky_locales.each do |locale|
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
@@ -1,5 +1,5 @@
1
1
  module Onesky
2
2
  module Rails
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -1,17 +1,29 @@
1
1
  namespace :onesky do
2
2
 
3
- desc "Upload string files of base locale to OneSky platform."
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 "Download translations from OneSky platform."
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("config/locales")
34
+ Rails.root.join('config/locales')
23
35
  end
24
36
 
25
37
  end
@@ -0,0 +1,13 @@
1
+ en:
2
+ week:
3
+ sun: Sunday
4
+ mon: Monday
5
+ tue: Tuesday
6
+ wed: Wednesday
7
+ thu: Thursday
8
+ fri: Friday
9
+ sat: Saturday
10
+ date:
11
+ year: Year
12
+ month: month
13
+ day: Day
@@ -0,0 +1,3 @@
1
+ en:
2
+ some: thing
3
+ i18n: internationalization
@@ -7,3 +7,7 @@ ja:
7
7
  thu: 木曜日
8
8
  fri: 金曜日
9
9
  sat: 土曜日
10
+ date:
11
+ year: 年
12
+ month: 月
13
+ day: 日
@@ -0,0 +1,3 @@
1
+ ja:
2
+ some: もの
3
+ i18n: 国際化
@@ -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 delete_test_dir
39
- if File.directory?(locale_dir)
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
- before(:each) do
46
- delete_test_dir
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
- after(:each) do
50
- delete_test_dir
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 from OneSky and save as YAML files' do
54
- prepare_download_requests!
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
- expect(locale_files).to be_empty
57
- client.download(file_path)
58
- expect(locale_files).to match_array(expected_locale_files)
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=#{file_name}",
96
+ 'Content-Disposition' => "attachment; filename=#{downloaded_file_name}",
67
97
  }
68
- query_string = "&source_file_name=#{file_name}&locale=ja"
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(file_path, file_name)),
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.2.0
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: 2015-07-13 00:00:00.000000000 Z
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/locales/en.json
137
- - spec/fixtures/locales/en.yml
138
- - spec/fixtures/locales/ja.yml
139
- - spec/fixtures/locales/special_en.yml
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/locales/en.json
169
- - spec/fixtures/locales/en.yml
170
- - spec/fixtures/locales/ja.yml
171
- - spec/fixtures/locales/special_en.yml
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
@@ -1,13 +0,0 @@
1
- {
2
- "en": {
3
- "week": {
4
- "sun": "Sunday",
5
- "mon": "Monday",
6
- "tue": "Tuesday",
7
- "wed": "Wednesday",
8
- "thu": "Thursday",
9
- "fri": "Friday",
10
- "sat": "Saturday"
11
- }
12
- }
13
- }