mc_translator 0.1.4 → 0.1.5
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/README.md +8 -4
- data/lib/mc_translator/version.rb +1 -1
- data/lib/mc_translator.rb +48 -35
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b11d17165b5bdb48084e3e2140d08991d41e82f369cf38b094b989e9aad8e60
|
4
|
+
data.tar.gz: 3ac28107c299d525c26bd6b94bf1619cd2b74c59b4ac20124a84080719534571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94235d4cb4bd896c59260b90629575f757f297de537f1e1c130e0d5b9844f75571fd765642ef8832bc49f7d4d63bb7c2c7c66997d3451efccf154ef5fbcf72ea
|
7
|
+
data.tar.gz: 90ff0afec54ab724a5a00abc1c198082ea522034f030fb8ddcae53de0d1c584ce17df5553ed07b1307102935df5ac33006d997e3982ba4b525891deeebc1d79e
|
data/README.md
CHANGED
@@ -25,13 +25,17 @@ Then, in your [Rakefile](https://github.com/yankaindustries/masterclass/blob/i18
|
|
25
25
|
require 'mc_translator'
|
26
26
|
```
|
27
27
|
|
28
|
-
Once you've got it installed, you'll need some basic configuration by adding a [.translations.yml](https://github.com/yankaindustries/masterclass/blob/i18n/mc_translator/.translator.yml):
|
28
|
+
Once you've got it installed, you'll need some basic configuration by setting up some ENV vars and adding a [.translations.yml](https://github.com/yankaindustries/masterclass/blob/i18n/mc_translator/.translator.yml):
|
29
|
+
|
30
|
+
```zsh
|
31
|
+
# .env.development
|
32
|
+
SMARTLING_USER_ID: xxxxxxxxxxxxxxxxxx
|
33
|
+
SMARTLING_USER_SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
34
|
+
SMARTLING_PROJECT_ID: xxxxxxx
|
35
|
+
```
|
29
36
|
|
30
37
|
```yaml
|
31
38
|
# .translations.yml
|
32
|
-
userId: xxxxxxxxxxxxxxxxxx
|
33
|
-
userSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
34
|
-
projectId: xxxxxxx
|
35
39
|
locales:
|
36
40
|
- en-GB
|
37
41
|
matches:
|
data/lib/mc_translator.rb
CHANGED
@@ -51,8 +51,13 @@ module McTranslator
|
|
51
51
|
YAML.safe_load(File.read('.translator.yml'))
|
52
52
|
end
|
53
53
|
|
54
|
+
def project_root(path = '.')
|
55
|
+
root = config['projectRoot'] || '.'
|
56
|
+
File.expand_path(File.join(Dir.getwd, root, path))
|
57
|
+
end
|
58
|
+
|
54
59
|
def git
|
55
|
-
Git.open(
|
60
|
+
Git.open(project_root('..'))
|
56
61
|
end
|
57
62
|
|
58
63
|
def origin
|
@@ -79,34 +84,32 @@ module McTranslator
|
|
79
84
|
|
80
85
|
def all_files
|
81
86
|
config['matches'].flat_map do |matcher|
|
82
|
-
Dir.glob(matcher['pattern']).map do |file|
|
87
|
+
Dir.glob(matcher['pattern'], base: config['projectRoot']).map do |file|
|
83
88
|
{ path: file, name: file, type: matcher['type'] }
|
84
89
|
end
|
85
90
|
end
|
86
91
|
end
|
87
92
|
|
88
93
|
def job_files
|
89
|
-
current_branch = git.current_branch
|
90
|
-
|
91
94
|
print_msg 'Getting job and files...'
|
92
|
-
job = @jobs.list['items'].detect { |j| j['jobName'] == current_branch }
|
95
|
+
job = @jobs.list['items'].detect { |j| j['jobName'] == git.current_branch }
|
93
96
|
@jobs.files(job['translationJobUid'])['items'].map do |file|
|
94
97
|
{ path: file['uri'], name: file['uri'] }
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
98
101
|
def push(files)
|
99
|
-
current_branch = git.current_branch
|
100
|
-
|
101
102
|
print_msg 'Setting up job...'
|
102
|
-
job = @jobs.find_or_create current_branch
|
103
|
+
job = @jobs.find_or_create git.current_branch
|
103
104
|
p job['translationJobUid']
|
104
105
|
|
105
106
|
print_msg 'Uploading files...'
|
106
107
|
files.each do |file|
|
107
|
-
p file[:path]
|
108
108
|
begin
|
109
|
-
|
109
|
+
name = file[:path]
|
110
|
+
path = File.join(project_root, file[:path])
|
111
|
+
p name, path
|
112
|
+
@files.upload path, name, file[:type]
|
110
113
|
@jobs.add_file job['translationJobUid'], file[:path], config['locales']
|
111
114
|
rescue => error
|
112
115
|
p error
|
@@ -121,41 +124,51 @@ module McTranslator
|
|
121
124
|
job = @jobs.detail job['translationJobUid']
|
122
125
|
p job['jobStatus']
|
123
126
|
|
124
|
-
if job['jobStatus'] == 'AWAITING_AUTHORIZATION'
|
125
|
-
|
126
|
-
|
127
|
-
end
|
127
|
+
# if job['jobStatus'] == 'AWAITING_AUTHORIZATION'
|
128
|
+
# print_msg 'Authorizing job...'
|
129
|
+
# @jobs.authorize job["translationJobUid"]
|
130
|
+
# end
|
128
131
|
|
129
132
|
job
|
130
133
|
end
|
131
134
|
|
132
135
|
def pull(files)
|
133
136
|
files
|
134
|
-
.map
|
137
|
+
.map { |file| file[:path] }
|
135
138
|
.each do |file|
|
136
139
|
config['locales'].each do |locale|
|
137
|
-
|
138
|
-
locale: locale,
|
139
|
-
dir: File.dirname(file),
|
140
|
-
name: File.basename(file, '.*').gsub(/en-US/, ''),
|
141
|
-
ext: File.extname(file),
|
142
|
-
}
|
143
|
-
|
144
|
-
name = File.expand_path(config['rewrite'] % expansion)
|
145
|
-
content = @files.download_translated(
|
146
|
-
file,
|
147
|
-
locale,
|
148
|
-
{ retrievalType: 'published' }
|
149
|
-
)
|
150
|
-
|
151
|
-
p file
|
152
|
-
p name
|
153
|
-
|
154
|
-
dir = File.dirname(name)
|
155
|
-
Dir.mkdir(dir) unless Dir.exist?(dir)
|
156
|
-
File.write(name, content)
|
140
|
+
pull_with_locale(file, locale, locale, 'published')
|
157
141
|
end
|
142
|
+
|
143
|
+
pull_with_locale(file, 'en-US', 'mc-US', 'pseudo')
|
158
144
|
end
|
159
145
|
end
|
146
|
+
|
147
|
+
def pull_with_locale(file, locale_on_smartling, locale_on_mc, type)
|
148
|
+
expansion = {
|
149
|
+
locale: locale_on_mc,
|
150
|
+
dir: File.dirname(file),
|
151
|
+
name: File.basename(file, '.*').gsub(/en-US/, ''),
|
152
|
+
ext: File.extname(file),
|
153
|
+
}
|
154
|
+
|
155
|
+
name = File.expand_path(config['rewrite'] % expansion)
|
156
|
+
content = @files.download_translated(
|
157
|
+
file,
|
158
|
+
locale_on_smartling,
|
159
|
+
retrievalType: type
|
160
|
+
)
|
161
|
+
|
162
|
+
p file
|
163
|
+
p name
|
164
|
+
|
165
|
+
if locale_on_smartling != locale_on_mc && /\.yml/ =~ name
|
166
|
+
content.sub!(Regexp.new(locale_on_smartling), locale_on_mc)
|
167
|
+
end
|
168
|
+
|
169
|
+
dir = File.dirname(name)
|
170
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
171
|
+
File.write(name, content)
|
172
|
+
end
|
160
173
|
end
|
161
174
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mc_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- justinjones53@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
111
|
+
rubygems_version: 3.0.3.1
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Translates locale files
|