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 +4 -4
- data/i18n_wigodo.gemspec +1 -1
- data/lib/i18n_wigodo.rb +0 -1
- data/lib/i18n_wigodo/tasks/wigodo.rake +40 -26
- data/lib/i18n_wigodo/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 678e25416451af890b1e6a89bc11184a92e4ba782712ba6a77cdeabf36645579
|
4
|
+
data.tar.gz: bab9592b702e715ea8e2d64596428486f2b7709822f101c7e2272c939067a0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bebd32cb1168779bd2e87d47e3760a26170afdb949155f0d24905b6bcf398983b0d860ce1cec3170e9a27ff9a798bbd18e4ca52cd38098aabefe99affddad60
|
7
|
+
data.tar.gz: cf3a7b8888c3a4448e90db0ffeb3cf1d5415a03068d435e79275707b2ed17a87a72d3eecaeff52567245e69b5d21d6bebecade806229d27b7ac6140cc585d740
|
data/i18n_wigodo.gemspec
CHANGED
@@ -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", "~>
|
36
|
+
spec.add_development_dependency "rake", "~> 12.3"
|
37
37
|
spec.add_development_dependency "rspec", "~> 3.0"
|
38
38
|
end
|
data/lib/i18n_wigodo.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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'
|
data/lib/i18n_wigodo/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
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
|