locize-cli 7.12.12 → 7.13.1
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.
- package/CHANGELOG.md +8 -0
- package/README.md +1 -1
- package/bin/locize +1 -0
- package/migrate.js +112 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
Project versioning adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
Change log format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
7
7
|
|
|
8
|
+
## [7.13.1](https://github.com/locize/locize-cli/compare/v7.13.0...v7.13.1) - 2022-12-08
|
|
9
|
+
|
|
10
|
+
- optimize migrate command
|
|
11
|
+
|
|
12
|
+
## [7.13.0](https://github.com/locize/locize-cli/compare/v7.12.12...v7.13.0) - 2022-12-08
|
|
13
|
+
|
|
14
|
+
- migrate command will use missing route if replace param is false or not passed and will also automaticaly create languages (make sure to use an api key with admin permissions)
|
|
15
|
+
|
|
8
16
|
## [7.12.12](https://github.com/locize/locize-cli/compare/v7.12.11...v7.12.12) - 2022-11-24
|
|
9
17
|
|
|
10
18
|
- update android-string-resource dependency to fix wrong plural unescaping
|
package/README.md
CHANGED
|
@@ -223,7 +223,7 @@ locize delete-namespace common --api-key my-api-key-d9de-4f55-9855-a9ef0ed44672
|
|
|
223
223
|
|
|
224
224
|
## Migration of existing i18next files
|
|
225
225
|
We suggest to use the sync command instead of the migrate command.
|
|
226
|
-
The migrate command
|
|
226
|
+
The migrate command should be used only once and only works with json files.
|
|
227
227
|
|
|
228
228
|
### Step 1: Go near to your translation files
|
|
229
229
|
|
package/bin/locize
CHANGED
|
@@ -79,6 +79,7 @@ program
|
|
|
79
79
|
apiKey: apiKey,
|
|
80
80
|
projectId: projectId,
|
|
81
81
|
addPath: addPath,
|
|
82
|
+
apiPath: url.parse(addPath).protocol + '//' + url.parse(addPath).host,
|
|
82
83
|
path: options.path,
|
|
83
84
|
language: options.language || config.language || config.lng || process.env.LOCIZE_LANGUAGE || process.env.LOCIZE_LANG || process.env.LOCIZE_LNG,
|
|
84
85
|
version: version,
|
package/migrate.js
CHANGED
|
@@ -4,6 +4,7 @@ const flatten = require('flat');
|
|
|
4
4
|
const async = require('async');
|
|
5
5
|
const colors = require('colors');
|
|
6
6
|
const request = require('./request');
|
|
7
|
+
const getRemoteLanguages = require('./getRemoteLanguages');
|
|
7
8
|
|
|
8
9
|
const getDirectories = (srcpath) => {
|
|
9
10
|
return fs.readdirSync(srcpath).filter(function(file) {
|
|
@@ -66,6 +67,8 @@ const transfer = (opt, ns, cb) => {
|
|
|
66
67
|
|
|
67
68
|
console.log(colors.yellow(`transfering ${opt.version}/${ns.language}/${ns.namespace}...`));
|
|
68
69
|
|
|
70
|
+
if (!opt.replace) url = url.replace('/update/', '/missing/');
|
|
71
|
+
|
|
69
72
|
request(url + `?replace=${!!opt.replace}`, {
|
|
70
73
|
method: 'post',
|
|
71
74
|
body: ns.value,
|
|
@@ -74,6 +77,11 @@ const transfer = (opt, ns, cb) => {
|
|
|
74
77
|
}
|
|
75
78
|
}, (err, res, obj) => {
|
|
76
79
|
if (err || (obj && (obj.errorMessage || obj.message))) {
|
|
80
|
+
if (url.indexOf('/missing/') > -1 && res.status === 412) {
|
|
81
|
+
console.log(colors.green(`transfered ${opt.version}/${ns.language}/${ns.namespace} (but all keys already existed)...`));
|
|
82
|
+
cb(null);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
77
85
|
console.log(colors.red(`transfer failed for ${opt.version}/${ns.language}/${ns.namespace}...`));
|
|
78
86
|
|
|
79
87
|
if (err) return cb(err);
|
|
@@ -86,14 +94,56 @@ const transfer = (opt, ns, cb) => {
|
|
|
86
94
|
};
|
|
87
95
|
|
|
88
96
|
const upload = (opt, nss, cb) => {
|
|
97
|
+
if (!opt.referenceLanguage) {
|
|
98
|
+
async.eachLimit(
|
|
99
|
+
nss,
|
|
100
|
+
require('os').cpus().length,
|
|
101
|
+
(ns, done) => transfer(opt, ns, done),
|
|
102
|
+
cb
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const nssRefLng = nss.filter((n) => n.language === opt.referenceLanguage);
|
|
108
|
+
const nssNonRefLng = nss.filter((n) => n.language !== opt.referenceLanguage);
|
|
109
|
+
|
|
89
110
|
async.eachLimit(
|
|
90
|
-
|
|
111
|
+
nssRefLng,
|
|
91
112
|
require('os').cpus().length,
|
|
92
113
|
(ns, done) => transfer(opt, ns, done),
|
|
93
|
-
|
|
114
|
+
(err) => {
|
|
115
|
+
if (err) return cb(err);
|
|
116
|
+
async.eachLimit(
|
|
117
|
+
nssNonRefLng,
|
|
118
|
+
require('os').cpus().length,
|
|
119
|
+
(ns, done) => transfer(opt, ns, done),
|
|
120
|
+
cb
|
|
121
|
+
);
|
|
122
|
+
}
|
|
94
123
|
);
|
|
95
124
|
};
|
|
96
125
|
|
|
126
|
+
const addLanguage = (opt, l, cb) => {
|
|
127
|
+
var url = opt.apiPath + '/language/' + opt.projectId + '/' + l;
|
|
128
|
+
|
|
129
|
+
request(url, {
|
|
130
|
+
method: 'post',
|
|
131
|
+
headers: {
|
|
132
|
+
'Authorization': opt.apiKey
|
|
133
|
+
}
|
|
134
|
+
}, (err, res, obj) => {
|
|
135
|
+
if (err || (obj && (obj.errorMessage || obj.message))) {
|
|
136
|
+
console.log(colors.red(`failed to add language ${l}...`));
|
|
137
|
+
|
|
138
|
+
if (err) return cb(err);
|
|
139
|
+
if (obj && (obj.errorMessage || obj.message)) return cb(new Error((obj.errorMessage || obj.message)));
|
|
140
|
+
}
|
|
141
|
+
if (res.status >= 300 && res.status !== 412) return cb(new Error(res.statusText + ' (' + res.status + ')'));
|
|
142
|
+
console.log(colors.green(`added language ${l}...`));
|
|
143
|
+
cb(null);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
97
147
|
const migrate = (opt, cb) => {
|
|
98
148
|
if (opt.format !== 'json') {
|
|
99
149
|
var err = new Error(`Format ${opt.format} is not accepted!`);
|
|
@@ -102,6 +152,8 @@ const migrate = (opt, cb) => {
|
|
|
102
152
|
return;
|
|
103
153
|
}
|
|
104
154
|
|
|
155
|
+
opt.apiPath = opt.apiPath || 'https://api.locize.app';
|
|
156
|
+
|
|
105
157
|
if (opt.language) {
|
|
106
158
|
const files = getFiles(opt.path);
|
|
107
159
|
|
|
@@ -142,17 +194,68 @@ const migrate = (opt, cb) => {
|
|
|
142
194
|
if (cb) cb(err);
|
|
143
195
|
return;
|
|
144
196
|
}
|
|
145
|
-
|
|
197
|
+
|
|
198
|
+
getRemoteLanguages(opt, (err, remoteLanguages) => {
|
|
146
199
|
if (err) {
|
|
147
|
-
if (!cb) {
|
|
148
|
-
console.error(colors.red(err.stack));
|
|
149
|
-
process.exit(1);
|
|
150
|
-
}
|
|
200
|
+
if (!cb) { console.error(colors.red(err.stack)); process.exit(1); }
|
|
151
201
|
if (cb) cb(err);
|
|
152
202
|
return;
|
|
153
203
|
}
|
|
154
|
-
|
|
155
|
-
|
|
204
|
+
|
|
205
|
+
const localLanguages = [];
|
|
206
|
+
nss.forEach((n) => {
|
|
207
|
+
if (localLanguages.indexOf(n.language) < 0) localLanguages.push(n.language);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const notExistingLanguages = localLanguages.filter((l) => remoteLanguages.indexOf(l) < 0);
|
|
211
|
+
|
|
212
|
+
if (notExistingLanguages.length === 0) {
|
|
213
|
+
upload(opt, nss, (err) => {
|
|
214
|
+
if (err) {
|
|
215
|
+
if (!cb) {
|
|
216
|
+
console.error(colors.red(err.stack));
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
if (cb) cb(err);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!cb) console.log(colors.green('FINISHED'));
|
|
223
|
+
if (cb) cb(null);
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async.eachLimit(
|
|
229
|
+
notExistingLanguages,
|
|
230
|
+
require('os').cpus().length,
|
|
231
|
+
(l, done) => addLanguage(opt, l, done),
|
|
232
|
+
(err) => {
|
|
233
|
+
if (err) {
|
|
234
|
+
if (!cb) {
|
|
235
|
+
console.error(colors.red(err.stack));
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
if (cb) cb(err);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
setTimeout(() => {
|
|
242
|
+
// wait a bit to make sure project is up-to-date also in cache
|
|
243
|
+
upload(opt, nss, (err) => {
|
|
244
|
+
if (err) {
|
|
245
|
+
if (!cb) {
|
|
246
|
+
console.error(colors.red(err.stack));
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
if (cb) cb(err);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!cb) console.log(colors.green('FINISHED'));
|
|
253
|
+
if (cb) cb(null);
|
|
254
|
+
});
|
|
255
|
+
}, 5000);
|
|
256
|
+
}
|
|
257
|
+
);
|
|
258
|
+
return;
|
|
156
259
|
});
|
|
157
260
|
});
|
|
158
261
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "locize-cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.1",
|
|
4
4
|
"description": "locize cli to import locales",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"xlsx": "0.18.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"eslint": "8.
|
|
36
|
+
"eslint": "8.29.0",
|
|
37
37
|
"gh-release": "6.0.4",
|
|
38
38
|
"pkg": "5.8.0"
|
|
39
39
|
},
|