google-spreadsheet-translation-sync 1.3.19 → 1.4.0
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 +6 -0
- package/index.js +5 -0
- package/package.json +1 -1
- package/src/export-to-spreadsheet.js +1 -1
- package/src/import-from-spreadsheet.js +26 -1
- package/test/test.js +44 -1
package/README.md
CHANGED
|
@@ -65,6 +65,12 @@ Default value: 'default'
|
|
|
65
65
|
|
|
66
66
|
If no locale is provided or could be parsed, the defaultLocaleName is used instead.
|
|
67
67
|
|
|
68
|
+
#### options.defaultFallback
|
|
69
|
+
Type: `Boolean`
|
|
70
|
+
Default value: `false`
|
|
71
|
+
|
|
72
|
+
Fills empty collumns automatically with the value from the defaultLocale - usefull if always complete translations have to be provided per file.
|
|
73
|
+
|
|
68
74
|
#### options.fileBaseName
|
|
69
75
|
Type: `String`
|
|
70
76
|
Default value: (empty string)
|
package/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The options type
|
|
5
|
+
* @typedef {{translationFormat: string, mode: string, spreadsheetId: string, gid : string, credentials: {}, keyId: string, fileBaseName: string, namespaces: boolean, defaultLocaleName: string, defaultFallback: boolean}} OptionsObject
|
|
6
|
+
*/
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Adds commas to a number
|
|
5
10
|
*/
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {[]} translationFiles - an array of files
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {OptionsObject} options
|
|
9
9
|
* @param {function} callback
|
|
10
10
|
*/
|
|
11
11
|
module.exports = function (translationFiles, options, callback) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param translationRootFolder
|
|
5
|
+
* @param {OptionsObject} options
|
|
6
|
+
* @param callback
|
|
7
|
+
*/
|
|
3
8
|
module.exports = function (translationRootFolder, options, callback) {
|
|
4
9
|
|
|
5
10
|
const connector = require('./connector');
|
|
@@ -74,6 +79,26 @@ module.exports = function (translationRootFolder, options, callback) {
|
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
if (options.defaultFallback) {
|
|
83
|
+
|
|
84
|
+
const defaultLocale = options.defaultLocaleName || 'default';
|
|
85
|
+
|
|
86
|
+
Object.keys(translationData).forEach(locale => {
|
|
87
|
+
// use the default locale as reference
|
|
88
|
+
Object.keys(translationData[defaultLocale]).forEach(namespace => {
|
|
89
|
+
if (!translationData[locale][namespace]) {
|
|
90
|
+
translationData[locale][namespace] = {};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Object.keys(translationData[defaultLocale][namespace]).forEach(key => {
|
|
94
|
+
if (translationData[locale][namespace][key] === undefined) {
|
|
95
|
+
translationData[locale][namespace][key] = translationData[defaultLocale][namespace][key];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
// now we get the handler
|
|
78
103
|
const h = require('./handler');
|
|
79
104
|
const TRANSLATION_FORMATS = require('./util/constraints').TRANSLATION_FORMATS;
|
package/test/test.js
CHANGED
|
@@ -54,7 +54,7 @@ function ensureFolder (folder) {
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
// const testFor = 'all' // 'connect', 'upload', 'import', 'properties', 'locale_json', 'gettext', 'yml', 'json_structure'
|
|
57
|
-
// const testFor = '
|
|
57
|
+
// const testFor = 'gettext';
|
|
58
58
|
const testFor = 'all';
|
|
59
59
|
|
|
60
60
|
const tests = [
|
|
@@ -403,6 +403,49 @@ const tests = [
|
|
|
403
403
|
const translationsPl = poPl.translations[''];
|
|
404
404
|
expect(translations.add_address.msgstr[0]).to.equal("Add new address");
|
|
405
405
|
expect(translationsPl['additional.news'].msgstr[0]).to.equal('czecz 2242');
|
|
406
|
+
expect(translationsPl.add_address).to.be.undefined;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
done();
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
{
|
|
415
|
+
name: 'should fill empty columns with the default',
|
|
416
|
+
run: ['import', 'gettext'],
|
|
417
|
+
fnc: function (done) {
|
|
418
|
+
this.timeout(timeout);
|
|
419
|
+
|
|
420
|
+
const baseName = 'om-mani-peme';
|
|
421
|
+
|
|
422
|
+
const options = {
|
|
423
|
+
translationFormat: 'gettext',
|
|
424
|
+
fileBaseName: baseName,
|
|
425
|
+
spreadsheetId: testSheetId_gettext,
|
|
426
|
+
credentials: accessData,
|
|
427
|
+
defaultLocaleName: 'en',
|
|
428
|
+
defaultFallback: true
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const translationRoot = ensureFolder(path.resolve('./test/translations/' + options.translationFormat + '/'));
|
|
432
|
+
const testFile = path.resolve(translationRoot + '/' + baseName + '-en.po');
|
|
433
|
+
const testFileDe = path.resolve(translationRoot + '/' + baseName + '-de.po');
|
|
434
|
+
|
|
435
|
+
app.importFromSpreadsheet(translationRoot, options, function (err) {
|
|
436
|
+
expect(err).to.be.null
|
|
437
|
+
|
|
438
|
+
if (!err) {
|
|
439
|
+
const fs = require('fs');
|
|
440
|
+
|
|
441
|
+
expect(fs.existsSync(testFile)).to.equal(true);
|
|
442
|
+
|
|
443
|
+
const po = require('gettext-parser').po.parse(fs.readFileSync(testFile));
|
|
444
|
+
const poDe = require('gettext-parser').po.parse(fs.readFileSync(testFileDe));
|
|
445
|
+
const translations = po.translations[''];
|
|
446
|
+
const translationsDe = poDe.translations[''];
|
|
447
|
+
expect(translations['additional.news'].msgstr[0]).to.equal("Additional News");
|
|
448
|
+
expect(translationsDe['additional.news']?.msgstr[0]).to.equal('Additional News');
|
|
406
449
|
}
|
|
407
450
|
|
|
408
451
|
done();
|