@vocab/phrase 0.0.0-global-key-support-20231025223328 → 0.0.0-master-20250202230611
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/dist/declarations/src/index.d.ts +2 -2
- package/dist/declarations/src/pull-translations.d.ts +1 -1
- package/dist/declarations/src/push-translations.d.ts +3 -2
- package/dist/vocab-phrase.cjs.d.ts +2 -1
- package/dist/vocab-phrase.cjs.dev.js +29 -32
- package/dist/vocab-phrase.cjs.prod.js +29 -32
- package/dist/vocab-phrase.esm.js +26 -27
- package/package.json +12 -6
- package/dist/declarations/src/csv.d.ts +0 -10
- package/dist/declarations/src/file.d.ts +0 -4
- package/dist/declarations/src/logger.d.ts +0 -3
- package/dist/declarations/src/phrase-api.d.ts +0 -12
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { pull } from
|
|
2
|
-
export { push } from
|
|
1
|
+
export { pull } from "./pull-translations.js";
|
|
2
|
+
export { push } from "./push-translations.js";
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type UserConfig } from '@vocab/core';
|
|
2
2
|
interface PushOptions {
|
|
3
3
|
branch: string;
|
|
4
4
|
deleteUnusedKeys?: boolean;
|
|
5
|
+
ignore?: string[];
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
8
|
* Uploads translations to the Phrase API for each language.
|
|
8
9
|
* A unique namespace is appended to each key using the file path the key came from.
|
|
9
10
|
*/
|
|
10
|
-
export declare function push({ branch, deleteUnusedKeys }: PushOptions, config: UserConfig): Promise<void>;
|
|
11
|
+
export declare function push({ branch, deleteUnusedKeys, ignore }: PushOptions, config: UserConfig): Promise<void>;
|
|
11
12
|
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./declarations/src/index";
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItcGhyYXNlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -5,18 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var core = require('@vocab/core');
|
|
8
|
-
var
|
|
9
|
-
var fetch = require('node-fetch');
|
|
10
|
-
var chalk = require('chalk');
|
|
8
|
+
var pc = require('picocolors');
|
|
11
9
|
var debug = require('debug');
|
|
12
10
|
var sync = require('csv-stringify/sync');
|
|
13
11
|
|
|
14
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
15
13
|
|
|
16
14
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
17
|
-
var
|
|
18
|
-
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
|
|
19
|
-
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
15
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
20
16
|
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
21
17
|
|
|
22
18
|
const mkdir = fs.promises.mkdir;
|
|
@@ -25,7 +21,7 @@ const writeFile = fs.promises.writeFile;
|
|
|
25
21
|
const trace = debug__default["default"](`vocab:phrase`);
|
|
26
22
|
const log = (...params) => {
|
|
27
23
|
// eslint-disable-next-line no-console
|
|
28
|
-
console.log(
|
|
24
|
+
console.log(pc__default["default"].yellow('Vocab'), ...params);
|
|
29
25
|
};
|
|
30
26
|
|
|
31
27
|
function translationsToCsv(translations, devLanguage) {
|
|
@@ -42,8 +38,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
42
38
|
const devLanguageRow = [...sharedData, message];
|
|
43
39
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
44
40
|
altLanguages.map(language => {
|
|
45
|
-
var _translations$languag
|
|
46
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
41
|
+
var _translations$languag;
|
|
42
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
47
43
|
if (altTranslationMessage) {
|
|
48
44
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
49
45
|
}
|
|
@@ -79,12 +75,12 @@ function _callPhrase(path, options = {}) {
|
|
|
79
75
|
if (!phraseApiToken) {
|
|
80
76
|
throw new Error('Missing PHRASE_API_TOKEN');
|
|
81
77
|
}
|
|
82
|
-
return
|
|
78
|
+
return fetch(path, {
|
|
83
79
|
...options,
|
|
84
80
|
headers: {
|
|
85
81
|
Authorization: `token ${phraseApiToken}`,
|
|
86
82
|
// Provide identification via User Agent as requested in https://developers.phrase.com/api/#overview--identification-via-user-agent
|
|
87
|
-
'User-Agent': '
|
|
83
|
+
'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
|
|
88
84
|
...options.headers
|
|
89
85
|
}
|
|
90
86
|
}).then(async response => {
|
|
@@ -135,10 +131,10 @@ async function pullAllTranslations(branch) {
|
|
|
135
131
|
const phraseResult = await callPhrase(`translations?branch=${branch}&per_page=100`);
|
|
136
132
|
const translations = {};
|
|
137
133
|
for (const r of phraseResult) {
|
|
138
|
-
if (!translations[r.locale.
|
|
139
|
-
translations[r.locale.
|
|
134
|
+
if (!translations[r.locale.name]) {
|
|
135
|
+
translations[r.locale.name] = {};
|
|
140
136
|
}
|
|
141
|
-
translations[r.locale.
|
|
137
|
+
translations[r.locale.name][r.key.name] = {
|
|
142
138
|
message: r.content
|
|
143
139
|
};
|
|
144
140
|
}
|
|
@@ -157,20 +153,18 @@ async function pushTranslations(translationsByLanguage, {
|
|
|
157
153
|
} = translationsToCsv(translationsByLanguage, devLanguage);
|
|
158
154
|
let devLanguageUploadId = '';
|
|
159
155
|
for (const [language, csvFileString] of Object.entries(csvFileStrings)) {
|
|
160
|
-
const formData = new
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
filename: `${language}.translations.csv`
|
|
165
|
-
});
|
|
156
|
+
const formData = new FormData();
|
|
157
|
+
formData.append('file', new Blob([csvFileString], {
|
|
158
|
+
type: 'text/csv'
|
|
159
|
+
}), `${language}.translations.csv`);
|
|
166
160
|
formData.append('file_format', 'csv');
|
|
167
161
|
formData.append('branch', branch);
|
|
168
162
|
formData.append('update_translations', 'true');
|
|
169
163
|
formData.append('update_descriptions', 'true');
|
|
170
|
-
formData.append(`locale_mapping[${language}]`, messageIndex);
|
|
171
|
-
formData.append('format_options[key_index]', keyIndex);
|
|
172
|
-
formData.append('format_options[comment_index]', commentIndex);
|
|
173
|
-
formData.append('format_options[tag_column]', tagColumn);
|
|
164
|
+
formData.append(`locale_mapping[${language}]`, messageIndex.toString());
|
|
165
|
+
formData.append('format_options[key_index]', keyIndex.toString());
|
|
166
|
+
formData.append('format_options[comment_index]', commentIndex.toString());
|
|
167
|
+
formData.append('format_options[tag_column]', tagColumn.toString());
|
|
174
168
|
formData.append('format_options[enable_pluralization]', 'false');
|
|
175
169
|
log(`Uploading translations for language ${language}`);
|
|
176
170
|
const result = await callPhrase(`uploads`, {
|
|
@@ -302,13 +296,20 @@ async function pull({
|
|
|
302
296
|
*/
|
|
303
297
|
async function push({
|
|
304
298
|
branch,
|
|
305
|
-
deleteUnusedKeys: deleteUnusedKeys$1
|
|
299
|
+
deleteUnusedKeys: deleteUnusedKeys$1,
|
|
300
|
+
ignore
|
|
306
301
|
}, config) {
|
|
302
|
+
if (ignore) {
|
|
303
|
+
trace(`ignoring files on paths: ${ignore.join(', ')}`);
|
|
304
|
+
}
|
|
307
305
|
const allLanguageTranslations = await core.loadAllTranslations({
|
|
308
306
|
fallbacks: 'none',
|
|
309
307
|
includeNodeModules: false,
|
|
310
308
|
withTags: true
|
|
311
|
-
},
|
|
309
|
+
}, {
|
|
310
|
+
...config,
|
|
311
|
+
ignore: [...(config.ignore || []), ...(ignore || [])]
|
|
312
|
+
});
|
|
312
313
|
trace(`Pushing translations to branch ${branch}`);
|
|
313
314
|
const allLanguages = config.languages.map(v => v.name);
|
|
314
315
|
await ensureBranch(branch);
|
|
@@ -329,7 +330,6 @@ async function push({
|
|
|
329
330
|
}
|
|
330
331
|
} = loadedTranslation;
|
|
331
332
|
for (const localKey of Object.keys(localTranslations)) {
|
|
332
|
-
var _globalKey;
|
|
333
333
|
const {
|
|
334
334
|
tags = [],
|
|
335
335
|
...localTranslation
|
|
@@ -337,11 +337,8 @@ async function push({
|
|
|
337
337
|
if (language === config.devLanguage) {
|
|
338
338
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
339
339
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
343
|
-
}
|
|
344
|
-
const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
340
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
341
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
345
342
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
346
343
|
}
|
|
347
344
|
}
|
|
@@ -5,18 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var core = require('@vocab/core');
|
|
8
|
-
var
|
|
9
|
-
var fetch = require('node-fetch');
|
|
10
|
-
var chalk = require('chalk');
|
|
8
|
+
var pc = require('picocolors');
|
|
11
9
|
var debug = require('debug');
|
|
12
10
|
var sync = require('csv-stringify/sync');
|
|
13
11
|
|
|
14
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
15
13
|
|
|
16
14
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
17
|
-
var
|
|
18
|
-
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
|
|
19
|
-
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
15
|
+
var pc__default = /*#__PURE__*/_interopDefault(pc);
|
|
20
16
|
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
21
17
|
|
|
22
18
|
const mkdir = fs.promises.mkdir;
|
|
@@ -25,7 +21,7 @@ const writeFile = fs.promises.writeFile;
|
|
|
25
21
|
const trace = debug__default["default"](`vocab:phrase`);
|
|
26
22
|
const log = (...params) => {
|
|
27
23
|
// eslint-disable-next-line no-console
|
|
28
|
-
console.log(
|
|
24
|
+
console.log(pc__default["default"].yellow('Vocab'), ...params);
|
|
29
25
|
};
|
|
30
26
|
|
|
31
27
|
function translationsToCsv(translations, devLanguage) {
|
|
@@ -42,8 +38,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
42
38
|
const devLanguageRow = [...sharedData, message];
|
|
43
39
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
44
40
|
altLanguages.map(language => {
|
|
45
|
-
var _translations$languag
|
|
46
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
41
|
+
var _translations$languag;
|
|
42
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
47
43
|
if (altTranslationMessage) {
|
|
48
44
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
49
45
|
}
|
|
@@ -79,12 +75,12 @@ function _callPhrase(path, options = {}) {
|
|
|
79
75
|
if (!phraseApiToken) {
|
|
80
76
|
throw new Error('Missing PHRASE_API_TOKEN');
|
|
81
77
|
}
|
|
82
|
-
return
|
|
78
|
+
return fetch(path, {
|
|
83
79
|
...options,
|
|
84
80
|
headers: {
|
|
85
81
|
Authorization: `token ${phraseApiToken}`,
|
|
86
82
|
// Provide identification via User Agent as requested in https://developers.phrase.com/api/#overview--identification-via-user-agent
|
|
87
|
-
'User-Agent': '
|
|
83
|
+
'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
|
|
88
84
|
...options.headers
|
|
89
85
|
}
|
|
90
86
|
}).then(async response => {
|
|
@@ -135,10 +131,10 @@ async function pullAllTranslations(branch) {
|
|
|
135
131
|
const phraseResult = await callPhrase(`translations?branch=${branch}&per_page=100`);
|
|
136
132
|
const translations = {};
|
|
137
133
|
for (const r of phraseResult) {
|
|
138
|
-
if (!translations[r.locale.
|
|
139
|
-
translations[r.locale.
|
|
134
|
+
if (!translations[r.locale.name]) {
|
|
135
|
+
translations[r.locale.name] = {};
|
|
140
136
|
}
|
|
141
|
-
translations[r.locale.
|
|
137
|
+
translations[r.locale.name][r.key.name] = {
|
|
142
138
|
message: r.content
|
|
143
139
|
};
|
|
144
140
|
}
|
|
@@ -157,20 +153,18 @@ async function pushTranslations(translationsByLanguage, {
|
|
|
157
153
|
} = translationsToCsv(translationsByLanguage, devLanguage);
|
|
158
154
|
let devLanguageUploadId = '';
|
|
159
155
|
for (const [language, csvFileString] of Object.entries(csvFileStrings)) {
|
|
160
|
-
const formData = new
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
filename: `${language}.translations.csv`
|
|
165
|
-
});
|
|
156
|
+
const formData = new FormData();
|
|
157
|
+
formData.append('file', new Blob([csvFileString], {
|
|
158
|
+
type: 'text/csv'
|
|
159
|
+
}), `${language}.translations.csv`);
|
|
166
160
|
formData.append('file_format', 'csv');
|
|
167
161
|
formData.append('branch', branch);
|
|
168
162
|
formData.append('update_translations', 'true');
|
|
169
163
|
formData.append('update_descriptions', 'true');
|
|
170
|
-
formData.append(`locale_mapping[${language}]`, messageIndex);
|
|
171
|
-
formData.append('format_options[key_index]', keyIndex);
|
|
172
|
-
formData.append('format_options[comment_index]', commentIndex);
|
|
173
|
-
formData.append('format_options[tag_column]', tagColumn);
|
|
164
|
+
formData.append(`locale_mapping[${language}]`, messageIndex.toString());
|
|
165
|
+
formData.append('format_options[key_index]', keyIndex.toString());
|
|
166
|
+
formData.append('format_options[comment_index]', commentIndex.toString());
|
|
167
|
+
formData.append('format_options[tag_column]', tagColumn.toString());
|
|
174
168
|
formData.append('format_options[enable_pluralization]', 'false');
|
|
175
169
|
log(`Uploading translations for language ${language}`);
|
|
176
170
|
const result = await callPhrase(`uploads`, {
|
|
@@ -302,13 +296,20 @@ async function pull({
|
|
|
302
296
|
*/
|
|
303
297
|
async function push({
|
|
304
298
|
branch,
|
|
305
|
-
deleteUnusedKeys: deleteUnusedKeys$1
|
|
299
|
+
deleteUnusedKeys: deleteUnusedKeys$1,
|
|
300
|
+
ignore
|
|
306
301
|
}, config) {
|
|
302
|
+
if (ignore) {
|
|
303
|
+
trace(`ignoring files on paths: ${ignore.join(', ')}`);
|
|
304
|
+
}
|
|
307
305
|
const allLanguageTranslations = await core.loadAllTranslations({
|
|
308
306
|
fallbacks: 'none',
|
|
309
307
|
includeNodeModules: false,
|
|
310
308
|
withTags: true
|
|
311
|
-
},
|
|
309
|
+
}, {
|
|
310
|
+
...config,
|
|
311
|
+
ignore: [...(config.ignore || []), ...(ignore || [])]
|
|
312
|
+
});
|
|
312
313
|
trace(`Pushing translations to branch ${branch}`);
|
|
313
314
|
const allLanguages = config.languages.map(v => v.name);
|
|
314
315
|
await ensureBranch(branch);
|
|
@@ -329,7 +330,6 @@ async function push({
|
|
|
329
330
|
}
|
|
330
331
|
} = loadedTranslation;
|
|
331
332
|
for (const localKey of Object.keys(localTranslations)) {
|
|
332
|
-
var _globalKey;
|
|
333
333
|
const {
|
|
334
334
|
tags = [],
|
|
335
335
|
...localTranslation
|
|
@@ -337,11 +337,8 @@ async function push({
|
|
|
337
337
|
if (language === config.devLanguage) {
|
|
338
338
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
339
339
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
343
|
-
}
|
|
344
|
-
const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
340
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
341
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
345
342
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
346
343
|
}
|
|
347
344
|
}
|
package/dist/vocab-phrase.esm.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { promises } from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { getAltLanguages, loadAllTranslations, getUniqueKey, getAltLanguageFilePath } from '@vocab/core';
|
|
4
|
-
import
|
|
5
|
-
import fetch from 'node-fetch';
|
|
6
|
-
import chalk from 'chalk';
|
|
4
|
+
import pc from 'picocolors';
|
|
7
5
|
import debug from 'debug';
|
|
8
6
|
import { stringify } from 'csv-stringify/sync';
|
|
9
7
|
|
|
@@ -13,7 +11,7 @@ const writeFile = promises.writeFile;
|
|
|
13
11
|
const trace = debug(`vocab:phrase`);
|
|
14
12
|
const log = (...params) => {
|
|
15
13
|
// eslint-disable-next-line no-console
|
|
16
|
-
console.log(
|
|
14
|
+
console.log(pc.yellow('Vocab'), ...params);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
17
|
function translationsToCsv(translations, devLanguage) {
|
|
@@ -30,8 +28,8 @@ function translationsToCsv(translations, devLanguage) {
|
|
|
30
28
|
const devLanguageRow = [...sharedData, message];
|
|
31
29
|
csvFilesByLanguage[devLanguage].push(devLanguageRow);
|
|
32
30
|
altLanguages.map(language => {
|
|
33
|
-
var _translations$languag
|
|
34
|
-
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0
|
|
31
|
+
var _translations$languag;
|
|
32
|
+
const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 || (_translations$languag = _translations$languag[key]) === null || _translations$languag === void 0 ? void 0 : _translations$languag.message;
|
|
35
33
|
if (altTranslationMessage) {
|
|
36
34
|
csvFilesByLanguage[language].push([...sharedData, altTranslationMessage]);
|
|
37
35
|
}
|
|
@@ -72,7 +70,7 @@ function _callPhrase(path, options = {}) {
|
|
|
72
70
|
headers: {
|
|
73
71
|
Authorization: `token ${phraseApiToken}`,
|
|
74
72
|
// Provide identification via User Agent as requested in https://developers.phrase.com/api/#overview--identification-via-user-agent
|
|
75
|
-
'User-Agent': '
|
|
73
|
+
'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
|
|
76
74
|
...options.headers
|
|
77
75
|
}
|
|
78
76
|
}).then(async response => {
|
|
@@ -123,10 +121,10 @@ async function pullAllTranslations(branch) {
|
|
|
123
121
|
const phraseResult = await callPhrase(`translations?branch=${branch}&per_page=100`);
|
|
124
122
|
const translations = {};
|
|
125
123
|
for (const r of phraseResult) {
|
|
126
|
-
if (!translations[r.locale.
|
|
127
|
-
translations[r.locale.
|
|
124
|
+
if (!translations[r.locale.name]) {
|
|
125
|
+
translations[r.locale.name] = {};
|
|
128
126
|
}
|
|
129
|
-
translations[r.locale.
|
|
127
|
+
translations[r.locale.name][r.key.name] = {
|
|
130
128
|
message: r.content
|
|
131
129
|
};
|
|
132
130
|
}
|
|
@@ -146,19 +144,17 @@ async function pushTranslations(translationsByLanguage, {
|
|
|
146
144
|
let devLanguageUploadId = '';
|
|
147
145
|
for (const [language, csvFileString] of Object.entries(csvFileStrings)) {
|
|
148
146
|
const formData = new FormData();
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
filename: `${language}.translations.csv`
|
|
153
|
-
});
|
|
147
|
+
formData.append('file', new Blob([csvFileString], {
|
|
148
|
+
type: 'text/csv'
|
|
149
|
+
}), `${language}.translations.csv`);
|
|
154
150
|
formData.append('file_format', 'csv');
|
|
155
151
|
formData.append('branch', branch);
|
|
156
152
|
formData.append('update_translations', 'true');
|
|
157
153
|
formData.append('update_descriptions', 'true');
|
|
158
|
-
formData.append(`locale_mapping[${language}]`, messageIndex);
|
|
159
|
-
formData.append('format_options[key_index]', keyIndex);
|
|
160
|
-
formData.append('format_options[comment_index]', commentIndex);
|
|
161
|
-
formData.append('format_options[tag_column]', tagColumn);
|
|
154
|
+
formData.append(`locale_mapping[${language}]`, messageIndex.toString());
|
|
155
|
+
formData.append('format_options[key_index]', keyIndex.toString());
|
|
156
|
+
formData.append('format_options[comment_index]', commentIndex.toString());
|
|
157
|
+
formData.append('format_options[tag_column]', tagColumn.toString());
|
|
162
158
|
formData.append('format_options[enable_pluralization]', 'false');
|
|
163
159
|
log(`Uploading translations for language ${language}`);
|
|
164
160
|
const result = await callPhrase(`uploads`, {
|
|
@@ -290,13 +286,20 @@ async function pull({
|
|
|
290
286
|
*/
|
|
291
287
|
async function push({
|
|
292
288
|
branch,
|
|
293
|
-
deleteUnusedKeys: deleteUnusedKeys$1
|
|
289
|
+
deleteUnusedKeys: deleteUnusedKeys$1,
|
|
290
|
+
ignore
|
|
294
291
|
}, config) {
|
|
292
|
+
if (ignore) {
|
|
293
|
+
trace(`ignoring files on paths: ${ignore.join(', ')}`);
|
|
294
|
+
}
|
|
295
295
|
const allLanguageTranslations = await loadAllTranslations({
|
|
296
296
|
fallbacks: 'none',
|
|
297
297
|
includeNodeModules: false,
|
|
298
298
|
withTags: true
|
|
299
|
-
},
|
|
299
|
+
}, {
|
|
300
|
+
...config,
|
|
301
|
+
ignore: [...(config.ignore || []), ...(ignore || [])]
|
|
302
|
+
});
|
|
300
303
|
trace(`Pushing translations to branch ${branch}`);
|
|
301
304
|
const allLanguages = config.languages.map(v => v.name);
|
|
302
305
|
await ensureBranch(branch);
|
|
@@ -317,7 +320,6 @@ async function push({
|
|
|
317
320
|
}
|
|
318
321
|
} = loadedTranslation;
|
|
319
322
|
for (const localKey of Object.keys(localTranslations)) {
|
|
320
|
-
var _globalKey;
|
|
321
323
|
const {
|
|
322
324
|
tags = [],
|
|
323
325
|
...localTranslation
|
|
@@ -325,11 +327,8 @@ async function push({
|
|
|
325
327
|
if (language === config.devLanguage) {
|
|
326
328
|
localTranslation.tags = [...tags, ...sharedTags];
|
|
327
329
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
331
|
-
}
|
|
332
|
-
const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
|
|
330
|
+
const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
|
|
331
|
+
const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
|
|
333
332
|
phraseTranslations[language][phraseKey] = localTranslation;
|
|
334
333
|
}
|
|
335
334
|
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocab/phrase",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-master-20250202230611",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/seek-oss/vocab.git",
|
|
7
|
+
"directory": "packages/phrase"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18"
|
|
11
|
+
},
|
|
4
12
|
"main": "dist/vocab-phrase.cjs.js",
|
|
5
13
|
"module": "dist/vocab-phrase.esm.js",
|
|
6
14
|
"author": "SEEK",
|
|
7
15
|
"license": "MIT",
|
|
8
16
|
"dependencies": {
|
|
9
|
-
"@vocab/core": "0.0.0-global-key-support-20231025223328",
|
|
10
|
-
"chalk": "^4.1.0",
|
|
11
17
|
"csv-stringify": "^6.2.3",
|
|
12
18
|
"debug": "^4.3.1",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
19
|
+
"picocolors": "^1.0.0",
|
|
20
|
+
"@vocab/core": "^1.6.3"
|
|
15
21
|
},
|
|
16
22
|
"devDependencies": {
|
|
17
23
|
"@types/debug": "^4.1.5",
|
|
18
|
-
"@types/node
|
|
24
|
+
"@types/node": "^18.11.9"
|
|
19
25
|
},
|
|
20
26
|
"files": [
|
|
21
27
|
"dist"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TranslationsByLanguage } from '@vocab/core';
|
|
2
|
-
export declare function translationsToCsv(translations: TranslationsByLanguage, devLanguage: string): {
|
|
3
|
-
csvFileStrings: {
|
|
4
|
-
[k: string]: string;
|
|
5
|
-
};
|
|
6
|
-
keyIndex: number;
|
|
7
|
-
messageIndex: number;
|
|
8
|
-
commentIndex: number;
|
|
9
|
-
tagColumn: number;
|
|
10
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TranslationsByLanguage } from '@vocab/core';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
|
-
export declare function callPhrase<T = any>(relativePath: string, options?: Parameters<typeof fetch>[1]): Promise<T>;
|
|
4
|
-
export declare function pullAllTranslations(branch: string): Promise<TranslationsByLanguage>;
|
|
5
|
-
export declare function pushTranslations(translationsByLanguage: TranslationsByLanguage, { devLanguage, branch }: {
|
|
6
|
-
devLanguage: string;
|
|
7
|
-
branch: string;
|
|
8
|
-
}): Promise<{
|
|
9
|
-
devLanguageUploadId: string;
|
|
10
|
-
}>;
|
|
11
|
-
export declare function deleteUnusedKeys(uploadId: string, branch: string): Promise<void>;
|
|
12
|
-
export declare function ensureBranch(branch: string): Promise<void>;
|