i18n-wigodo 0.1.0 → 0.1.2

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
  SHA256:
3
- metadata.gz: a1054d855d99494af20ccd3fa9cd9aeb870d573ee92cf7a8eb6615ae782a4b9f
4
- data.tar.gz: f3f15be5d8a3dc36b7a34a0aeef0e28c14f0214e15afb477587dbef733439a97
3
+ metadata.gz: 678e25416451af890b1e6a89bc11184a92e4ba782712ba6a77cdeabf36645579
4
+ data.tar.gz: bab9592b702e715ea8e2d64596428486f2b7709822f101c7e2272c939067a0b7
5
5
  SHA512:
6
- metadata.gz: 1507ce9dea67a15356fd1c683632fd1d10b6748473ffae135e9bb0b96bc00c684dbe72addecfa9108937654f8444ec83bf000a6716ce4452a9841d66f7727dea
7
- data.tar.gz: 77ef961c5b87558434c5f4cc8a48dc26ca872c4dad2290a207c7430e2842945a84d6925a963c168f47139f541c67c4a4628fdbc2be1c57dfc248c6d8d62b84f6
6
+ metadata.gz: 4bebd32cb1168779bd2e87d47e3760a26170afdb949155f0d24905b6bcf398983b0d860ce1cec3170e9a27ff9a798bbd18e4ca52cd38098aabefe99affddad60
7
+ data.tar.gz: cf3a7b8888c3a4448e90db0ffeb3cf1d5415a03068d435e79275707b2ed17a87a72d3eecaeff52567245e69b5d21d6bebecade806229d27b7ac6140cc585d740
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.require_paths = ["lib"]
34
34
 
35
35
  spec.add_development_dependency "bundler", "~> 1.16"
36
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", "~> 12.3"
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
38
  end
@@ -2,5 +2,4 @@ require 'i18n_wigodo/version'
2
2
  require 'i18n_wigodo/railtie' if defined?(Rails)
3
3
 
4
4
  module I18nWigodo
5
- # Your code goes here...
6
5
  end
@@ -1,6 +1,20 @@
1
1
  require 'net/http'
2
+ require 'uri'
2
3
  require 'csv'
3
4
 
5
+ def fetch_with_redirect(uri_str, limit = 10)
6
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
7
+
8
+ url = URI.parse(uri_str)
9
+ response = Net::HTTP.start(url.host, url.port, use_ssl: true) { |http| http.get(url.path + (url.query ? "?#{url.query}" : "")) }
10
+ case response
11
+ when Net::HTTPRedirection then fetch_with_redirect(response['location'], limit - 1)
12
+ when Net::HTTPSuccess then response
13
+ else
14
+ response.error!
15
+ end
16
+ end
17
+
4
18
  namespace :wigodo do
5
19
  desc 'Import translations from Google Drive'
6
20
  task :fetch do
@@ -17,39 +31,39 @@ namespace :wigodo do
17
31
  "https://docs.google.com/spreadsheets/d/1en5BoKGaAqO9_BRSQ9CQKkvwrYQWNBUPjgSzxyn83Pc/edit#gid=0")
18
32
  end
19
33
 
20
- Net::HTTP.start("docs.google.com", 443, use_ssl: true) do |http|
21
- resp = http.get("/spreadsheets/d/#{document_id}/export?format=csv")
22
- #puts resp.body.force_encoding('UTF-8')
23
- rows = CSV.parse(resp.body.force_encoding('UTF-8'))
24
- locales = rows.first[2..-1]
25
- default_locale_index = 2
34
+ resp = fetch_with_redirect("https://docs.google.com/spreadsheets/d/#{document_id}/export?format=csv")
26
35
 
27
- hash = {}
28
- locales.each do |locale|
29
- locale_index = locales.find_index(locale) + 2
30
- hash[locale] = {}
31
- rows[1..-1].each do |cols|
32
- if cols.first.present?
33
- last_item = hash[locale]
34
- keys = cols.first.split('.')
35
- keys[0..-2].each do |key|
36
- last_item = last_item[key] ||= {}
37
- end
38
- content = cols[locale_index]
39
- default_content = cols[default_locale_index]
40
- last_item[keys[-1]] = content.present? ? content : default_content
36
+ # puts resp.body.force_encoding('UTF-8')
37
+ rows = CSV.parse(resp.body.force_encoding('UTF-8'))
38
+ locales = rows.first[2..-1]
39
+ default_locale_index = 2
40
+
41
+ hash = {}
42
+ locales.each do |locale|
43
+ locale_index = locales.find_index(locale) + 2
44
+ hash[locale] = {}
45
+ rows[1..-1].each do |cols|
46
+ if cols.first.present?
47
+ last_item = hash[locale]
48
+ keys = cols.first.split('.')
49
+ keys[0..-2].each do |key|
50
+ last_item = last_item[key] ||= {}
41
51
  end
52
+ content = cols[locale_index]
53
+ default_content = cols[default_locale_index]
54
+ last_item[keys[-1]] = content.present? ? content : default_content
42
55
  end
56
+ end
43
57
 
44
- filename = "#{Rails.root}/config/locales/remote.#{locale}.yml"
45
- print "generating #{filename}..."
46
- File.open(filename, "w") do |f|
47
- f.write({locale => hash[locale]}.to_yaml)
48
- end
49
- puts "OK"
58
+ filename = "#{Rails.root}/config/locales/remote.#{locale}.yml"
59
+ print "generating #{filename}..."
60
+ File.open(filename, "w") do |f|
61
+ f.write({locale => hash[locale]}.to_yaml)
50
62
  end
63
+ puts "OK"
51
64
  end
52
65
  end
66
+
53
67
  desc 'Output a CSV style file with existing translations (to be imported into Google Spreadsheets)'
54
68
  task export: :environment do
55
69
  require 'yaml'
@@ -1,3 +1,3 @@
1
1
  module I18nWigodo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-wigodo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Malte Münchert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-11 00:00:00.000000000 Z
11
+ date: 2020-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -96,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.7.5
99
+ rubygems_version: 3.1.4
101
100
  signing_key:
102
101
  specification_version: 4
103
102
  summary: Fetch translations from a Google Doc spreadsheet