google-spreadsheet-translation-sync 1.3.9 → 1.3.11
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/README.md +8 -1
- package/package.json +1 -1
- package/src/export-to-spreadsheet.js +3 -1
- package/src/import-from-spreadsheet.js +3 -0
- package/test/test.js +18 -13
package/README.md
CHANGED
|
@@ -20,8 +20,15 @@ gsTransSync.exportToSpreadsheet(['de.json', 'en.json'], options, callback);
|
|
|
20
20
|
gsTransSync.importFromSpreadsheet('your/folder', { spreadsheetId: 'xxxxxxx'}, function () {
|
|
21
21
|
// done :)
|
|
22
22
|
});
|
|
23
|
-
|
|
24
23
|
```
|
|
24
|
+
|
|
25
|
+
On the Google spreadsheets side, this needs to have the following structure:
|
|
26
|
+
|
|
27
|
+
|key|default|de|en|... any other locale|<locale> # <comment>|
|
|
28
|
+
|---|---|---|---|---|---|
|
|
29
|
+
|test.something|Test Schlüssel|Test Key|****||
|
|
30
|
+
|
|
31
|
+
Please not the line `<locale> # <comment>` - `# <comment>` will be ignored in uploads and downloads, so you can put some information for your translators into the google doc (They will do it anyway, so this way you don't need to remove the comment before import).
|
|
25
32
|
|
|
26
33
|
### Options
|
|
27
34
|
|
package/package.json
CHANGED
|
@@ -160,7 +160,9 @@ module.exports = function (translationFiles, options, callback) {
|
|
|
160
160
|
|
|
161
161
|
// this is the header row
|
|
162
162
|
if (cell.value) {
|
|
163
|
-
|
|
163
|
+
// clear comments from the header name
|
|
164
|
+
let cleanLocale = cell.value.split('#')[0].trim();
|
|
165
|
+
headerIndexMap[cellIndex] = keyIndexMap[cleanLocale];
|
|
164
166
|
maxIndex = cellIndex
|
|
165
167
|
} else {
|
|
166
168
|
// this looks like an initial upload, let's do it
|
|
@@ -42,6 +42,9 @@ module.exports = function (translationRootFolder, options, callback) {
|
|
|
42
42
|
|
|
43
43
|
if (rowIndex === 0) {
|
|
44
44
|
if (val) {
|
|
45
|
+
// clear comments from the header
|
|
46
|
+
val = val.split('#')[0].trim();
|
|
47
|
+
|
|
45
48
|
headers[cellIndex] = val;
|
|
46
49
|
if (cellIndex > keyCellIndex) {
|
|
47
50
|
translationData[val] = {};
|
package/test/test.js
CHANGED
|
@@ -9,11 +9,11 @@ const accessData = require('./data/google-test-access.json');
|
|
|
9
9
|
const tmp = require('tmp');
|
|
10
10
|
const async = require('async');
|
|
11
11
|
|
|
12
|
-
const testSheetId = '1ZJK1G_3wrEo9lnu1FenjOzSy3uoAi-RLWbph1cI6DWI';
|
|
12
|
+
const testSheetId = '1ZJK1G_3wrEo9lnu1FenjOzSy3uoAi-RLWbph1cI6DWI'; // https://docs.google.com/spreadsheets/d/1ZJK1G_3wrEo9lnu1FenjOzSy3uoAi-RLWbph1cI6DWI/edit#gid=0
|
|
13
13
|
const testWorksheetId = '1209225803';
|
|
14
|
-
const testSheetId_gettext = '1CRvX4TCxUGCcs_MtKC5BdEViHYzYzLXdqtbuVaAXfKc';
|
|
15
|
-
const testSheetId_properties = '1Z0Mpbf6lgdGiuiHlpb9DENVfKxkxSRwcfQEDYrgokEE';
|
|
16
|
-
const testSheetId_yaml = '1Ml3jLK6RgbPQ4e7XZpILvB-XWMeziHpwdxS8r4AYNtE';
|
|
14
|
+
const testSheetId_gettext = '1CRvX4TCxUGCcs_MtKC5BdEViHYzYzLXdqtbuVaAXfKc'; // https://docs.google.com/spreadsheets/d/1CRvX4TCxUGCcs_MtKC5BdEViHYzYzLXdqtbuVaAXfKc/edit#gid=0
|
|
15
|
+
const testSheetId_properties = '1Z0Mpbf6lgdGiuiHlpb9DENVfKxkxSRwcfQEDYrgokEE'; // https://docs.google.com/spreadsheets/d/1Z0Mpbf6lgdGiuiHlpb9DENVfKxkxSRwcfQEDYrgokEE/edit#gid=0
|
|
16
|
+
const testSheetId_yaml = '1Ml3jLK6RgbPQ4e7XZpILvB-XWMeziHpwdxS8r4AYNtE'; // https://docs.google.com/spreadsheets/d/1Ml3jLK6RgbPQ4e7XZpILvB-XWMeziHpwdxS8r4AYNtE/edit#gid=0
|
|
17
17
|
const timeout = 20000;
|
|
18
18
|
|
|
19
19
|
// preparations
|
|
@@ -21,10 +21,6 @@ const timeout = 20000;
|
|
|
21
21
|
var tmpFile = tmp.fileSync({postfix: '.csv'});
|
|
22
22
|
|
|
23
23
|
const csv = require('fast-csv');
|
|
24
|
-
const fileUtils = require("../src/util/file-utils");
|
|
25
|
-
const yamlHandler = require("../src/handlers/yaml");
|
|
26
|
-
const rimraf = require("rimraf");
|
|
27
|
-
const yaml = require("js-yaml");
|
|
28
24
|
const testFile = tmpFile.name;
|
|
29
25
|
const csvData = [
|
|
30
26
|
['key', 'default', 'de', 'it', 'fr', 'pl', 'hu'],
|
|
@@ -202,7 +198,7 @@ const tests = [
|
|
|
202
198
|
}).then(function (rows) {
|
|
203
199
|
expect(rows).to.have.lengthOf((csvData.length - 1) * 2);
|
|
204
200
|
expect(rows[0][options.keyId]).to.equal(csvData[1][0]);
|
|
205
|
-
expect(rows[0]
|
|
201
|
+
expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
|
|
206
202
|
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
207
203
|
expect(rows[0].hu).to.equal('Elfogadom');
|
|
208
204
|
expect(rows[0].namespace).to.equal(namespaces[0]);
|
|
@@ -281,7 +277,7 @@ const tests = [
|
|
|
281
277
|
}).then(function (rows) {
|
|
282
278
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
283
279
|
expect(rows[0][options.keyId]).to.equal(csvData[1][0]);
|
|
284
|
-
expect(rows[0]
|
|
280
|
+
expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
|
|
285
281
|
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
286
282
|
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
287
283
|
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
@@ -323,12 +319,15 @@ const tests = [
|
|
|
323
319
|
|
|
324
320
|
if (!err) {
|
|
325
321
|
const testFile = path.resolve(translationRoot + '/other.properties');
|
|
322
|
+
const testFilePl = path.resolve(translationRoot + '/other_pl.properties');
|
|
326
323
|
const PropertiesReader = require('properties-reader');
|
|
327
324
|
|
|
328
325
|
const props = PropertiesReader(testFile);
|
|
326
|
+
const propsPl = PropertiesReader(testFilePl);
|
|
329
327
|
|
|
330
328
|
// expect(Object.keys(props.getAllProperties()).length).to.equal(csvData.length - 1); // without the header
|
|
331
329
|
expect(props.get(csvData[2][0])).to.equal(csvData[2][1]);
|
|
330
|
+
expect(propsPl.get(csvData[1][0])).to.equal(csvData[1][5]);
|
|
332
331
|
}
|
|
333
332
|
|
|
334
333
|
done();
|
|
@@ -352,15 +351,18 @@ const tests = [
|
|
|
352
351
|
|
|
353
352
|
const translationRoot = ensureFolder(path.resolve('./test/translations/' + options.translationFormat + '/'));
|
|
354
353
|
const testFile = path.resolve(translationRoot + '/default.json');
|
|
354
|
+
const testFilePl = path.resolve(translationRoot + '/pl.json');
|
|
355
355
|
|
|
356
356
|
app.importFromSpreadsheet(translationRoot, options, function (err) {
|
|
357
357
|
expect(err).to.be.null
|
|
358
358
|
|
|
359
359
|
if (!err) {
|
|
360
360
|
const defaultKeys = require(testFile);
|
|
361
|
+
const plKeys = require(testFilePl);
|
|
361
362
|
|
|
362
363
|
// expect(Object.keys(defaultKeys).length).to.equal(326);
|
|
363
364
|
expect(defaultKeys[csvData[2][0]]).to.equal(csvData[2][1]);
|
|
365
|
+
expect(plKeys[csvData[1][0]]).to.equal(csvData[1][5]);
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
done();
|
|
@@ -385,6 +387,7 @@ const tests = [
|
|
|
385
387
|
|
|
386
388
|
const translationRoot = ensureFolder(path.resolve('./test/translations/' + options.translationFormat + '/'));
|
|
387
389
|
const testFile = path.resolve(translationRoot + '/' + baseName + '-en.po');
|
|
390
|
+
const testFilePl = path.resolve(translationRoot + '/' + baseName + '-pl.po');
|
|
388
391
|
|
|
389
392
|
app.importFromSpreadsheet(translationRoot, options, function (err) {
|
|
390
393
|
expect(err).to.be.null
|
|
@@ -395,9 +398,11 @@ const tests = [
|
|
|
395
398
|
expect(fs.existsSync(testFile)).to.equal(true);
|
|
396
399
|
|
|
397
400
|
const po = require('gettext-parser').po.parse(fs.readFileSync(testFile));
|
|
401
|
+
const poPl = require('gettext-parser').po.parse(fs.readFileSync(testFilePl));
|
|
398
402
|
const translations = po.translations[''];
|
|
399
|
-
|
|
403
|
+
const translationsPl = poPl.translations[''];
|
|
400
404
|
expect(translations.add_address.msgstr[0]).to.equal("Add new address");
|
|
405
|
+
expect(translationsPl['additional.news'].msgstr[0]).to.equal('czecz 2242');
|
|
401
406
|
}
|
|
402
407
|
|
|
403
408
|
done();
|
|
@@ -462,7 +467,7 @@ const tests = [
|
|
|
462
467
|
}).then(function (rows) {
|
|
463
468
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
464
469
|
expect(rows[0][options.keyId]).to.equal(csvData[1][0]);
|
|
465
|
-
expect(rows[0]
|
|
470
|
+
expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
|
|
466
471
|
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
467
472
|
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
468
473
|
expect(rows[1].default).to.equal(csvData[2][1]);
|
|
@@ -575,7 +580,7 @@ const tests = [
|
|
|
575
580
|
}).then(function (rows) {
|
|
576
581
|
expect(rows).to.have.lengthOf(csvData.length - 1);
|
|
577
582
|
expect(rows[0][options.keyId]).to.equal(csvData[1][0]);
|
|
578
|
-
expect(rows[0]
|
|
583
|
+
expect(rows[0]['pl # with comment']).to.equal(csvData[1][5]);
|
|
579
584
|
expect(rows[0].default).to.equal(csvData[1][1]);
|
|
580
585
|
expect(rows[0].hu).to.equal('Elfogadom'); // this was not part of the upload and should not be overwrittem
|
|
581
586
|
expect(rows[1].default).to.equal(csvData[2][1]);
|