@vocab/phrase 0.0.0-global-key-support-20231025223328 → 0.0.0-master-20240711232538

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.
@@ -1,2 +1,2 @@
1
- export { pull } from './pull-translations';
2
- export { push } from './push-translations';
1
+ export { pull } from "./pull-translations.js";
2
+ export { push } from "./push-translations.js";
@@ -1,4 +1,4 @@
1
- import type { UserConfig } from '@vocab/core';
1
+ import { type UserConfig } from '@vocab/core';
2
2
  interface PullOptions {
3
3
  branch?: string;
4
4
  deleteUnusedKeys?: boolean;
@@ -1,4 +1,4 @@
1
- import type { UserConfig } from '@vocab/core';
1
+ import { type UserConfig } from '@vocab/core';
2
2
  interface PushOptions {
3
3
  branch: string;
4
4
  deleteUnusedKeys?: boolean;
@@ -1 +1,2 @@
1
1
  export * from "./declarations/src/index";
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 FormData = require('form-data');
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 FormData__default = /*#__PURE__*/_interopDefault(FormData);
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(chalk__default["default"].yellow('Vocab'), ...params);
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, _translations$languag2;
46
- const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 ? void 0 : (_translations$languag2 = _translations$languag[key]) === null || _translations$languag2 === void 0 ? void 0 : _translations$languag2.message;
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 fetch__default["default"](path, {
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': 'SEEK Demo Candidate App (jhope@seek.com.au)',
83
+ 'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
88
84
  ...options.headers
89
85
  }
90
86
  }).then(async response => {
@@ -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 FormData__default["default"]();
161
- const fileContents = Buffer.from(csvFileString);
162
- formData.append('file', fileContents, {
163
- contentType: 'text/csv',
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`, {
@@ -329,7 +323,6 @@ async function push({
329
323
  }
330
324
  } = loadedTranslation;
331
325
  for (const localKey of Object.keys(localTranslations)) {
332
- var _globalKey;
333
326
  const {
334
327
  tags = [],
335
328
  ...localTranslation
@@ -337,11 +330,8 @@ async function push({
337
330
  if (language === config.devLanguage) {
338
331
  localTranslation.tags = [...tags, ...sharedTags];
339
332
  }
340
- let globalKey;
341
- if (loadedTranslation.languages[config.devLanguage][localKey].globalKey) {
342
- globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
343
- }
344
- const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
333
+ const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
334
+ const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
345
335
  phraseTranslations[language][phraseKey] = localTranslation;
346
336
  }
347
337
  }
@@ -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 FormData = require('form-data');
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 FormData__default = /*#__PURE__*/_interopDefault(FormData);
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(chalk__default["default"].yellow('Vocab'), ...params);
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, _translations$languag2;
46
- const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 ? void 0 : (_translations$languag2 = _translations$languag[key]) === null || _translations$languag2 === void 0 ? void 0 : _translations$languag2.message;
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 fetch__default["default"](path, {
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': 'SEEK Demo Candidate App (jhope@seek.com.au)',
83
+ 'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
88
84
  ...options.headers
89
85
  }
90
86
  }).then(async response => {
@@ -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 FormData__default["default"]();
161
- const fileContents = Buffer.from(csvFileString);
162
- formData.append('file', fileContents, {
163
- contentType: 'text/csv',
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`, {
@@ -329,7 +323,6 @@ async function push({
329
323
  }
330
324
  } = loadedTranslation;
331
325
  for (const localKey of Object.keys(localTranslations)) {
332
- var _globalKey;
333
326
  const {
334
327
  tags = [],
335
328
  ...localTranslation
@@ -337,11 +330,8 @@ async function push({
337
330
  if (language === config.devLanguage) {
338
331
  localTranslation.tags = [...tags, ...sharedTags];
339
332
  }
340
- let globalKey;
341
- if (loadedTranslation.languages[config.devLanguage][localKey].globalKey) {
342
- globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
343
- }
344
- const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
333
+ const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
334
+ const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : core.getUniqueKey(localKey, loadedTranslation.namespace);
345
335
  phraseTranslations[language][phraseKey] = localTranslation;
346
336
  }
347
337
  }
@@ -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 FormData from 'form-data';
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(chalk.yellow('Vocab'), ...params);
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, _translations$languag2;
34
- const altTranslationMessage = (_translations$languag = translations[language]) === null || _translations$languag === void 0 ? void 0 : (_translations$languag2 = _translations$languag[key]) === null || _translations$languag2 === void 0 ? void 0 : _translations$languag2.message;
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': 'SEEK Demo Candidate App (jhope@seek.com.au)',
73
+ 'User-Agent': 'Vocab Client (https://github.com/seek-oss/vocab)',
76
74
  ...options.headers
77
75
  }
78
76
  }).then(async response => {
@@ -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
- const fileContents = Buffer.from(csvFileString);
150
- formData.append('file', fileContents, {
151
- contentType: 'text/csv',
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`, {
@@ -317,7 +313,6 @@ async function push({
317
313
  }
318
314
  } = loadedTranslation;
319
315
  for (const localKey of Object.keys(localTranslations)) {
320
- var _globalKey;
321
316
  const {
322
317
  tags = [],
323
318
  ...localTranslation
@@ -325,11 +320,8 @@ async function push({
325
320
  if (language === config.devLanguage) {
326
321
  localTranslation.tags = [...tags, ...sharedTags];
327
322
  }
328
- let globalKey;
329
- if (loadedTranslation.languages[config.devLanguage][localKey].globalKey) {
330
- globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
331
- }
332
- const phraseKey = (_globalKey = globalKey) !== null && _globalKey !== void 0 ? _globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
323
+ const globalKey = loadedTranslation.languages[config.devLanguage][localKey].globalKey;
324
+ const phraseKey = globalKey !== null && globalKey !== void 0 ? globalKey : getUniqueKey(localKey, loadedTranslation.namespace);
333
325
  phraseTranslations[language][phraseKey] = localTranslation;
334
326
  }
335
327
  }
package/package.json CHANGED
@@ -1,21 +1,27 @@
1
1
  {
2
2
  "name": "@vocab/phrase",
3
- "version": "0.0.0-global-key-support-20231025223328",
3
+ "version": "0.0.0-master-20240711232538",
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
- "form-data": "^3.0.0",
14
- "node-fetch": "^2.6.1"
19
+ "picocolors": "^1.0.0",
20
+ "@vocab/core": "^1.6.2"
15
21
  },
16
22
  "devDependencies": {
17
23
  "@types/debug": "^4.1.5",
18
- "@types/node-fetch": "^2.5.7"
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,4 +0,0 @@
1
- /// <reference types="node" />
2
- import { promises as fs } from 'fs';
3
- export declare const mkdir: typeof fs.mkdir;
4
- export declare const writeFile: typeof fs.writeFile;
@@ -1,3 +0,0 @@
1
- import debug from 'debug';
2
- export declare const trace: debug.Debugger;
3
- export declare const log: (...params: unknown[]) => void;
@@ -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>;