zci 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +3 -3
- data/bin/zci +0 -1
- data/lib/zci/commands/02_import.rb +34 -3
- data/lib/zci/commands/04_export.rb +29 -1
- data/lib/zci/export.rb +15 -0
- data/lib/zci/import.rb +27 -0
- data/lib/zci/version.rb +1 -1
- data/zci.gemspec +10 -10
- metadata +27 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f95dfd3865ea558bfcaa22e60e2285677ce24d
|
4
|
+
data.tar.gz: c01a0ee589285d9ebe4c1d0cdc891a73934c09a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cf98dec90c1c9d2cd63006ee18040ce7cf672fd329dbea961161c7ebf36160e410e93fd31298f911c5c86fdef51e19617c95e51ab98e4d474be8b28b38c4bff
|
7
|
+
data.tar.gz: 834020525511063185091a22c85aa8a41e7e3cdfde559dfe6bb190101b8455217faf23231ef083f81209a9c6c441cf8b4eb9f92dd577a573869687d51d49522e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/README.md
CHANGED
@@ -102,8 +102,8 @@ categories:
|
|
102
102
|
|
103
103
|
Tested with the following Ruby versions:
|
104
104
|
|
105
|
-
- MRI 2.2.
|
106
|
-
- JRuby 9.0.0.0
|
105
|
+
- MRI 2.2.3
|
106
|
+
- JRuby 9.0.0.0
|
107
107
|
|
108
108
|
## Contributing
|
109
109
|
|
@@ -117,6 +117,6 @@ Tested with the following Ruby versions:
|
|
117
117
|
|
118
118
|
Author: Anton Maminov (anton.maminov@gmail.com)
|
119
119
|
|
120
|
-
Copyright: 2015-
|
120
|
+
Copyright: 2015-2017 [crowdin.com](http://crowdin.com/)
|
121
121
|
|
122
122
|
This project is licensed under the MIT license, a copy of which can be found in the LICENSE file.
|
data/bin/zci
CHANGED
@@ -21,7 +21,14 @@ command :'import:sources' do |c|
|
|
21
21
|
|
22
22
|
# Check if Category exists in Zendesk
|
23
23
|
source_category = @zendesk.hc_categories.find(id: source_category_id)
|
24
|
-
|
24
|
+
|
25
|
+
if source_category.nil? || source_category.id != source_category_id
|
26
|
+
puts "[Zendesk] No category with id #{source_category_id}"
|
27
|
+
next
|
28
|
+
end
|
29
|
+
|
30
|
+
category_xml = build_category_xml(source_category)
|
31
|
+
category_hash = build_category_hash(source_category).merge({ xml: category_xml })
|
25
32
|
|
26
33
|
# Get category's sections in Zendesk
|
27
34
|
puts "[Zendesk] Get sections for Category with id #{source_category_id}"
|
@@ -67,6 +74,30 @@ command :'import:sources' do |c|
|
|
67
74
|
@crowdin.change_directory(source_category_id.to_s, title: source_category.attributes[:name])
|
68
75
|
end
|
69
76
|
|
77
|
+
# Create xml file for category and upload to Crowdin
|
78
|
+
file_name = "category_#{category_hash[:id]}.xml"
|
79
|
+
|
80
|
+
o = File.new(File.join(resources_category_dir, file_name), 'w')
|
81
|
+
o.write(category_hash[:xml].to_xml)
|
82
|
+
o.close
|
83
|
+
|
84
|
+
files = [
|
85
|
+
{
|
86
|
+
source: File.join(resources_category_dir, file_name),
|
87
|
+
dest: File.join(source_category_id.to_s, file_name),
|
88
|
+
export_pattern: '/%two_letters_code%/%original_path%/%original_file_name%',
|
89
|
+
title: category_hash[:name]
|
90
|
+
}
|
91
|
+
]
|
92
|
+
|
93
|
+
if remote_project_tree[:files].include?("/#{source_category_id}/#{file_name}")
|
94
|
+
puts "[Crowdin] Update category file `#{file_name}`"
|
95
|
+
@crowdin.update_file(files, type: 'webxml')
|
96
|
+
else
|
97
|
+
puts "[Crowdin] Add category file `#{file_name}`"
|
98
|
+
@crowdin.add_file(files, type: 'webxml')
|
99
|
+
end
|
100
|
+
|
70
101
|
# Creates xml files for sections and upload to Crowdin
|
71
102
|
sections_builder.each do |section|
|
72
103
|
file_name = "section_#{section[:id]}.xml"
|
@@ -79,7 +110,7 @@ command :'import:sources' do |c|
|
|
79
110
|
{
|
80
111
|
source: File.join(resources_category_dir, file_name),
|
81
112
|
dest: File.join(source_category_id.to_s, file_name),
|
82
|
-
|
113
|
+
export_pattern: '/%two_letters_code%/%original_path%/%original_file_name%',
|
83
114
|
title: section[:name]
|
84
115
|
}
|
85
116
|
]
|
@@ -105,7 +136,7 @@ command :'import:sources' do |c|
|
|
105
136
|
{
|
106
137
|
source: File.join(resources_category_dir, file_name),
|
107
138
|
dest: File.join(source_category_id.to_s, file_name),
|
108
|
-
|
139
|
+
export_pattern: '/%two_letters_code%/%original_path%/%original_file_name%',
|
109
140
|
title: article[:title]
|
110
141
|
}
|
111
142
|
]
|
@@ -14,12 +14,21 @@ command :'export:translations' do |c|
|
|
14
14
|
@cli_config['categories'].each do |category|
|
15
15
|
@zendesk.locales.select { |locale| !locale.default? }.each do |locale|
|
16
16
|
if lang = category['translations'].detect { |tr| tr['zendesk_locale'].casecmp(locale.locale) == 0 }
|
17
|
+
category_xml_files = Dir["#{resources_dir}/#{lang['crowdin_language_code']}/#{category['zendesk_category']}/category_*.xml"]
|
17
18
|
section_xml_files = Dir["#{resources_dir}/#{lang['crowdin_language_code']}/#{category['zendesk_category']}/section_*.xml"]
|
18
19
|
article_xml_files = Dir["#{resources_dir}/#{lang['crowdin_language_code']}/#{category['zendesk_category']}/article_*.xml"]
|
19
20
|
|
21
|
+
all_categories = []
|
20
22
|
all_sections = []
|
21
23
|
all_articles = []
|
22
24
|
|
25
|
+
# Read categories from XML files
|
26
|
+
category_xml_files.each do |file|
|
27
|
+
category_xml_file = File.read(file)
|
28
|
+
category = parse_category_xml(category_xml_file)
|
29
|
+
all_categories << category
|
30
|
+
end
|
31
|
+
|
23
32
|
# Read sections from XML files
|
24
33
|
section_xml_files.each do |file|
|
25
34
|
section_xml_file = File.read(file)
|
@@ -34,6 +43,25 @@ command :'export:translations' do |c|
|
|
34
43
|
all_articles << article
|
35
44
|
end
|
36
45
|
|
46
|
+
### Categories
|
47
|
+
#
|
48
|
+
categories = @zendesk.hc_categories
|
49
|
+
all_categories.each do |category_hash|
|
50
|
+
if category = categories.find(id: category_hash[:id])
|
51
|
+
if category_tr = category.translations.detect { |tr| tr.locale.casecmp(locale.locale) == 0 }
|
52
|
+
category_tr.update(title: category_hash[:name], body: category_hash[:description])
|
53
|
+
if category_tr.changed?
|
54
|
+
category_tr.save
|
55
|
+
puts "[Zendesk] Update `#{lang['crowdin_language_code']}` language translation for Category\##{category.id}."
|
56
|
+
end
|
57
|
+
else
|
58
|
+
category_tr = category.translations.build(locale: locale.locale, title: category_hash[:name], body: category_hash[:description])
|
59
|
+
category_tr.save
|
60
|
+
puts "[Zendesk] Create `#{lang['crowdin_language_code']}` language translation for Category\##{category.id}."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
37
65
|
### Sections
|
38
66
|
#
|
39
67
|
sections = @zendesk.sections
|
@@ -46,7 +74,7 @@ command :'export:translations' do |c|
|
|
46
74
|
puts "[Zendesk] Update `#{lang['crowdin_language_code']}` language translation for Section\##{section.id}."
|
47
75
|
end
|
48
76
|
else
|
49
|
-
section_tr = section.translations.build(locale: locale.locale,
|
77
|
+
section_tr = section.translations.build(locale: locale.locale, title: section_hash[:name], body: section_hash[:description])
|
50
78
|
section_tr.save
|
51
79
|
puts "[Zendesk] Create `#{lang['crowdin_language_code']}` language translation for Section\##{section.id}."
|
52
80
|
end
|
data/lib/zci/export.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
module ZCI
|
2
|
+
|
3
|
+
def parse_category_xml(xml_file)
|
4
|
+
doc = Nokogiri::XML.parse(xml_file)
|
5
|
+
category_xml = doc.xpath("//category").first
|
6
|
+
|
7
|
+
category = {
|
8
|
+
id: category_xml[:id],
|
9
|
+
name: category_xml.xpath('name').text,
|
10
|
+
description: category_xml.xpath('description').text,
|
11
|
+
position: category_xml[:position],
|
12
|
+
}
|
13
|
+
|
14
|
+
return category
|
15
|
+
end
|
16
|
+
|
2
17
|
def parse_section_xml(xml_file)
|
3
18
|
doc = Nokogiri::XML.parse(xml_file)
|
4
19
|
section_xml = doc.xpath("//section").first
|
data/lib/zci/import.rb
CHANGED
@@ -1,4 +1,31 @@
|
|
1
1
|
module ZCI
|
2
|
+
|
3
|
+
def build_category_xml(category)
|
4
|
+
category_xml = Nokogiri::XML::Builder.new do |xml|
|
5
|
+
xml.root {
|
6
|
+
xml.category(id: category.id, position: category.position, identifier: 'category', type: 'document') {
|
7
|
+
xml.name {
|
8
|
+
xml.cdata category.name
|
9
|
+
}
|
10
|
+
xml.description {
|
11
|
+
xml.cdata category.description
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
return category_xml
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_category_hash(category)
|
21
|
+
return {
|
22
|
+
id: category.id,
|
23
|
+
position: category.position,
|
24
|
+
name: category.name,
|
25
|
+
description: category.description,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
2
29
|
def build_section_xml(section)
|
3
30
|
section_xml = Nokogiri::XML::Builder.new do |xml|
|
4
31
|
xml.root {
|
data/lib/zci/version.rb
CHANGED
data/zci.gemspec
CHANGED
@@ -6,6 +6,7 @@ spec = Gem::Specification.new do |s|
|
|
6
6
|
s.author = 'Anton Maminov'
|
7
7
|
s.email = 'anton.maminov@gmail.com'
|
8
8
|
s.homepage = 'https://github.com/mamantoha/zci'
|
9
|
+
s.license = 'MIT'
|
9
10
|
s.platform = Gem::Platform::RUBY
|
10
11
|
s.summary = 'Zendesk and Crowdin integration Command Line Interface (CLI)'
|
11
12
|
s.files = `git ls-files`.split("\n")
|
@@ -15,14 +16,13 @@ spec = Gem::Specification.new do |s|
|
|
15
16
|
# s.rdoc_options << '--title' << 'zci' << '--main' << 'README.rdoc' << '-ri'
|
16
17
|
s.bindir = 'bin'
|
17
18
|
s.executables << 'zci'
|
18
|
-
s.add_runtime_dependency
|
19
|
-
s.add_runtime_dependency
|
20
|
-
s.add_runtime_dependency
|
21
|
-
s.add_runtime_dependency
|
22
|
-
s.add_runtime_dependency
|
23
|
-
s.add_runtime_dependency
|
24
|
-
s.add_development_dependency
|
25
|
-
s.add_development_dependency
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency('byebug')
|
19
|
+
s.add_runtime_dependency 'nokogiri', '~> 0'
|
20
|
+
s.add_runtime_dependency 'rubyzip', '~> 0'
|
21
|
+
s.add_runtime_dependency 'crowdin-api','~> 0'
|
22
|
+
s.add_runtime_dependency 'zendesk_api','~> 0'
|
23
|
+
s.add_runtime_dependency 'zendesk_help_center_api', '~> 0.1.0'
|
24
|
+
s.add_runtime_dependency 'gli', '~> 0'
|
25
|
+
s.add_development_dependency 'rake','~> 0'
|
26
|
+
s.add_development_dependency 'rdoc', '~> 0'
|
27
|
+
s.add_development_dependency 'aruba', '~> 0'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,153 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Maminov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubyzip
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: crowdin-api
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: zendesk_api
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: zendesk_help_center_api
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.1.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: gli
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rdoc
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: aruba
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - "
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: byebug
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
129
|
+
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
131
|
version: '0'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
|
-
- - "
|
136
|
+
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: '0'
|
153
139
|
description:
|
@@ -183,7 +169,8 @@ files:
|
|
183
169
|
- zci.gemspec
|
184
170
|
- zci.yml.example
|
185
171
|
homepage: https://github.com/mamantoha/zci
|
186
|
-
licenses:
|
172
|
+
licenses:
|
173
|
+
- MIT
|
187
174
|
metadata: {}
|
188
175
|
post_install_message:
|
189
176
|
rdoc_options: []
|
@@ -202,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
189
|
version: '0'
|
203
190
|
requirements: []
|
204
191
|
rubyforge_project:
|
205
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.6.11
|
206
193
|
signing_key:
|
207
194
|
specification_version: 4
|
208
195
|
summary: Zendesk and Crowdin integration Command Line Interface (CLI)
|