@vocab/phrase 0.0.0-phrase-pull-dev-language-202281412540
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 +128 -0
- package/dist/declarations/src/file.d.ts +4 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/logger.d.ts +3 -0
- package/dist/declarations/src/phrase-api.d.ts +7 -0
- package/dist/declarations/src/pull-translations.d.ts +6 -0
- package/dist/declarations/src/push-translations.d.ts +9 -0
- package/dist/vocab-phrase.cjs.d.ts +1 -0
- package/dist/vocab-phrase.cjs.dev.js +261 -0
- package/dist/vocab-phrase.cjs.js +7 -0
- package/dist/vocab-phrase.cjs.prod.js +261 -0
- package/dist/vocab-phrase.esm.js +248 -0
- package/package.json +19 -0
- package/src/file.ts +4 -0
- package/src/index.ts +2 -0
- package/src/logger.ts +9 -0
- package/src/phrase-api.ts +147 -0
- package/src/pull-translations.test.ts +250 -0
- package/src/pull-translations.ts +119 -0
- package/src/push-translations.test.ts +77 -0
- package/src/push-translations.ts +55 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @vocab/phrase
|
|
2
|
+
|
|
3
|
+
## 0.0.0-phrase-pull-dev-language-202281412540
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ac206c8`](https://github.com/seek-oss/vocab/commit/ac206c8ba997551d960f0b72474568c1850f9561) [#91](https://github.com/seek-oss/vocab/pull/91) Thanks [@askoufis](https://github.com/askoufis)! - Improve error message when Phrase doesn't return any translations for the dev language
|
|
8
|
+
|
|
9
|
+
## 1.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`20eec77`](https://github.com/seek-oss/vocab/commit/20eec770705d05048ad8b32575cb92720b887f5b) [#76](https://github.com/seek-oss/vocab/pull/76) Thanks [@askoufis](https://github.com/askoufis)! - `vocab pull` no longer errors when phrase returns no translations for a configured language
|
|
14
|
+
|
|
15
|
+
## 1.0.0
|
|
16
|
+
|
|
17
|
+
### Major Changes
|
|
18
|
+
|
|
19
|
+
- [`3031054`](https://github.com/seek-oss/vocab/commit/303105440851db6126f0606e1607745b27dd981c) [#51](https://github.com/seek-oss/vocab/pull/51) Thanks [@jahredhope](https://github.com/jahredhope)! - Release v1.0.0
|
|
20
|
+
|
|
21
|
+
Release Vocab as v1.0.0 to signify a stable API and support future [semver versioning](https://semver.org/) releases.
|
|
22
|
+
|
|
23
|
+
Vocab has seen a lot of iteration and changes since it was first published on 20 November 2020. We are now confident with the API and believe Vocab is ready for common use.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`0074382`](https://github.com/seek-oss/vocab/commit/007438273ef70f5d5ded45777933651ad8df36f6), [`3031054`](https://github.com/seek-oss/vocab/commit/303105440851db6126f0606e1607745b27dd981c)]:
|
|
28
|
+
- @vocab/core@1.0.0
|
|
29
|
+
- @vocab/types@1.0.0
|
|
30
|
+
|
|
31
|
+
## 0.0.11
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [[`5b1fdc0`](https://github.com/seek-oss/vocab/commit/5b1fdc019522b12e7ef94b2fec57b54a9310d41c)]:
|
|
36
|
+
- @vocab/core@0.0.11
|
|
37
|
+
- @vocab/types@0.0.9
|
|
38
|
+
|
|
39
|
+
## 0.0.10
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Updated dependencies [[`7c96a14`](https://github.com/seek-oss/vocab/commit/7c96a142f602132d38c1df1a47a1f4657dc5c94c)]:
|
|
44
|
+
- @vocab/core@0.0.10
|
|
45
|
+
|
|
46
|
+
## 0.0.9
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [[`3034bd3`](https://github.com/seek-oss/vocab/commit/3034bd3de610a9d1f3bfbd8caefa27064dee2710), [`c110745`](https://github.com/seek-oss/vocab/commit/c110745b79df1a8ade6b1d8a49e798b04a7b95e1)]:
|
|
51
|
+
- @vocab/core@0.0.9
|
|
52
|
+
|
|
53
|
+
## 0.0.8
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- Updated dependencies [[`f2fca67`](https://github.com/seek-oss/vocab/commit/f2fca679c66ae65405a0aa24f0a0e472026aad0d)]:
|
|
58
|
+
- @vocab/core@0.0.8
|
|
59
|
+
- @vocab/types@0.0.8
|
|
60
|
+
|
|
61
|
+
## 0.0.7
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- [`283bcad`](https://github.com/seek-oss/vocab/commit/283bcada06e622ab14ed891743ed3f55cf09e245) [#33](https://github.com/seek-oss/vocab/pull/33) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Move all vocab files to single directory with configurable suffix
|
|
66
|
+
|
|
67
|
+
- Updated dependencies [[`283bcad`](https://github.com/seek-oss/vocab/commit/283bcada06e622ab14ed891743ed3f55cf09e245), [`ad0d240`](https://github.com/seek-oss/vocab/commit/ad0d2404545ded8e11621eae8f29467ff3352366), [`f3992ef`](https://github.com/seek-oss/vocab/commit/f3992efbf08939ebf853fac650a49cc46dc51dfb), [`f3992ef`](https://github.com/seek-oss/vocab/commit/f3992efbf08939ebf853fac650a49cc46dc51dfb)]:
|
|
68
|
+
- @vocab/core@0.0.7
|
|
69
|
+
- @vocab/types@0.0.7
|
|
70
|
+
|
|
71
|
+
## 0.0.6
|
|
72
|
+
|
|
73
|
+
### Patch Changes
|
|
74
|
+
|
|
75
|
+
- [`80a46c0`](https://github.com/seek-oss/vocab/commit/80a46c01a55408675f5822c3618519f80136c3ab) [#27](https://github.com/seek-oss/vocab/pull/27) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Add `ignore` config for ignoring files/folders from cli scripts
|
|
76
|
+
|
|
77
|
+
* [`80a46c0`](https://github.com/seek-oss/vocab/commit/80a46c01a55408675f5822c3618519f80136c3ab) [#27](https://github.com/seek-oss/vocab/pull/27) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Ignore node_modules from push, pull and compile scripts
|
|
78
|
+
|
|
79
|
+
* Updated dependencies [[`80a46c0`](https://github.com/seek-oss/vocab/commit/80a46c01a55408675f5822c3618519f80136c3ab), [`80a46c0`](https://github.com/seek-oss/vocab/commit/80a46c01a55408675f5822c3618519f80136c3ab)]:
|
|
80
|
+
- @vocab/core@0.0.6
|
|
81
|
+
- @vocab/types@0.0.6
|
|
82
|
+
|
|
83
|
+
## 0.0.5
|
|
84
|
+
|
|
85
|
+
### Patch Changes
|
|
86
|
+
|
|
87
|
+
- Updated dependencies [[`371ed16`](https://github.com/seek-oss/vocab/commit/371ed16a232a04dab13afa7e2b352dfb6724eea4), [`c222d68`](https://github.com/seek-oss/vocab/commit/c222d68a3c0c24723a338eccb959798881f6a118)]:
|
|
88
|
+
- @vocab/core@0.0.5
|
|
89
|
+
|
|
90
|
+
## 0.0.4
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- [`5f5c581`](https://github.com/seek-oss/vocab/commit/5f5c581a65bff28729ee19e1ec0bdea488a9d6c2) [#19](https://github.com/seek-oss/vocab/pull/19) Thanks [@jahredhope](https://github.com/jahredhope)! - Compile useable TypeScript importable files with `vocab compile`.
|
|
95
|
+
|
|
96
|
+
The new `vocab compile` step replaces `vocab generate-types` in creating a fully functional **translations.ts** file.
|
|
97
|
+
|
|
98
|
+
This allows vocab to be used **without the Webpack Plugin**, however use of the plugin is still heavily advised to ensure optimal loading of translation content on the web.
|
|
99
|
+
|
|
100
|
+
Support for unit testing is now better than ever! The newly created **translations.ts** means your unit test code will see the same code as available while rendering.
|
|
101
|
+
|
|
102
|
+
See the [documentation](https://github.com/seek-oss/vocab) for further usage details.
|
|
103
|
+
|
|
104
|
+
* [`02f943c`](https://github.com/seek-oss/vocab/commit/02f943ca892913b41f9e4720a72400777cf14b3d) [#17](https://github.com/seek-oss/vocab/pull/17) Thanks [@jahredhope](https://github.com/jahredhope)! - Add additional debug traces
|
|
105
|
+
|
|
106
|
+
* Updated dependencies [[`5f5c581`](https://github.com/seek-oss/vocab/commit/5f5c581a65bff28729ee19e1ec0bdea488a9d6c2), [`02f943c`](https://github.com/seek-oss/vocab/commit/02f943ca892913b41f9e4720a72400777cf14b3d)]:
|
|
107
|
+
- @vocab/core@0.0.4
|
|
108
|
+
- @vocab/types@0.0.5
|
|
109
|
+
|
|
110
|
+
## 0.0.3
|
|
111
|
+
|
|
112
|
+
### Patch Changes
|
|
113
|
+
|
|
114
|
+
- [`08de30d`](https://github.com/seek-oss/vocab/commit/08de30d338c2a5ebdcf14da7c736dddf22e7ca9e) [#14](https://github.com/seek-oss/vocab/pull/14) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Add ability to override files namespace with \$namespace
|
|
115
|
+
|
|
116
|
+
* [`26b52f4`](https://github.com/seek-oss/vocab/commit/26b52f4878ded440841e08c858bdc9e685500c2a) [#16](https://github.com/seek-oss/vocab/pull/16) Thanks [@jahredhope](https://github.com/jahredhope)! - Enable debugging with DEBUG environment variable
|
|
117
|
+
|
|
118
|
+
* Updated dependencies [[`08de30d`](https://github.com/seek-oss/vocab/commit/08de30d338c2a5ebdcf14da7c736dddf22e7ca9e), [`ed6cf40`](https://github.com/seek-oss/vocab/commit/ed6cf408973f2e9c4d07a71fcb52f40294ebaf65), [`26b52f4`](https://github.com/seek-oss/vocab/commit/26b52f4878ded440841e08c858bdc9e685500c2a), [`b5a5a05`](https://github.com/seek-oss/vocab/commit/b5a5a05a5bb87b48e6e9160af75f555728143ea2)]:
|
|
119
|
+
- @vocab/core@0.0.3
|
|
120
|
+
- @vocab/types@0.0.4
|
|
121
|
+
|
|
122
|
+
## 0.0.2
|
|
123
|
+
|
|
124
|
+
### Patch Changes
|
|
125
|
+
|
|
126
|
+
- Updated dependencies [[`4710f34`](https://github.com/seek-oss/vocab/commit/4710f341f2827643e3eff69ef7e26d44ec6e8a2b), [`4710f34`](https://github.com/seek-oss/vocab/commit/4710f341f2827643e3eff69ef7e26d44ec6e8a2b)]:
|
|
127
|
+
- @vocab/types@0.0.3
|
|
128
|
+
- @vocab/core@0.0.2
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TranslationsByKey } from './../../types/src/index';
|
|
2
|
+
import type { TranslationsByLanguage } from '@vocab/types';
|
|
3
|
+
import fetch from 'node-fetch';
|
|
4
|
+
export declare function callPhrase(relativePath: string, options?: Parameters<typeof fetch>[1]): Promise<any>;
|
|
5
|
+
export declare function pullAllTranslations(branch: string): Promise<TranslationsByLanguage>;
|
|
6
|
+
export declare function pushTranslationsByLocale(contents: TranslationsByKey, locale: string, branch: string): Promise<void>;
|
|
7
|
+
export declare function ensureBranch(branch: string): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UserConfig } from '@vocab/types';
|
|
2
|
+
interface PushOptions {
|
|
3
|
+
branch: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Uploading to the Phrase API for each language. Adding a unique namespace to each key using file path they key came from
|
|
7
|
+
*/
|
|
8
|
+
export declare function push({ branch }: PushOptions, config: UserConfig): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var core = require('@vocab/core');
|
|
8
|
+
var FormData = require('form-data');
|
|
9
|
+
var fetch = require('node-fetch');
|
|
10
|
+
var chalk = require('chalk');
|
|
11
|
+
var debug = require('debug');
|
|
12
|
+
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
16
|
+
var FormData__default = /*#__PURE__*/_interopDefault(FormData);
|
|
17
|
+
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
|
|
18
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
19
|
+
var debug__default = /*#__PURE__*/_interopDefault(debug);
|
|
20
|
+
|
|
21
|
+
const mkdir = fs.promises.mkdir;
|
|
22
|
+
const writeFile = fs.promises.writeFile;
|
|
23
|
+
|
|
24
|
+
const trace = debug__default['default'](`vocab:phrase`);
|
|
25
|
+
const log = (...params) => {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log(chalk__default['default'].yellow('Vocab'), ...params);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function _callPhrase(path, options = {}) {
|
|
31
|
+
const phraseApiToken = process.env.PHRASE_API_TOKEN;
|
|
32
|
+
|
|
33
|
+
if (!phraseApiToken) {
|
|
34
|
+
throw new Error('Missing PHRASE_API_TOKEN');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return fetch__default['default'](path, { ...options,
|
|
38
|
+
headers: {
|
|
39
|
+
Authorization: `token ${phraseApiToken}`,
|
|
40
|
+
// Provide identification via User Agent as requested in https://developers.phrase.com/api/#overview--identification-via-user-agent
|
|
41
|
+
'User-Agent': 'SEEK Demo Candidate App (jhope@seek.com.au)',
|
|
42
|
+
...options.headers
|
|
43
|
+
}
|
|
44
|
+
}).then(async response => {
|
|
45
|
+
console.log(`${path}: ${response.status} - ${response.statusText}`);
|
|
46
|
+
console.log(`Rate Limit: ${response.headers.get('X-Rate-Limit-Remaining')} of ${response.headers.get('X-Rate-Limit-Limit')} remaining. (${response.headers.get('X-Rate-Limit-Reset')} seconds remaining})`);
|
|
47
|
+
console.log('\nLink:', response.headers.get('Link'), '\n'); // Print All Headers:
|
|
48
|
+
// console.log(Array.from(r.headers.entries()));
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
var _response$headers$get;
|
|
52
|
+
|
|
53
|
+
const result = await response.json();
|
|
54
|
+
console.log(`Internal Result (Length: ${result.length})\n`);
|
|
55
|
+
|
|
56
|
+
if ((!options.method || options.method === 'GET') && (_response$headers$get = response.headers.get('Link')) !== null && _response$headers$get !== void 0 && _response$headers$get.includes('rel=next')) {
|
|
57
|
+
var _response$headers$get2, _response$headers$get3;
|
|
58
|
+
|
|
59
|
+
const [, nextPageUrl] = (_response$headers$get2 = (_response$headers$get3 = response.headers.get('Link')) === null || _response$headers$get3 === void 0 ? void 0 : _response$headers$get3.match(/<([^>]*)>; rel=next/)) !== null && _response$headers$get2 !== void 0 ? _response$headers$get2 : [];
|
|
60
|
+
|
|
61
|
+
if (!nextPageUrl) {
|
|
62
|
+
throw new Error('Cant parse next page URL');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log('Results recieved with next page: ', nextPageUrl);
|
|
66
|
+
const nextPageResult = await _callPhrase(nextPageUrl, options);
|
|
67
|
+
return [...result, ...nextPageResult];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.error('Unable to parse response as JSON', e);
|
|
73
|
+
return response.text();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function callPhrase(relativePath, options = {}) {
|
|
79
|
+
const projectId = process.env.PHRASE_PROJECT_ID;
|
|
80
|
+
|
|
81
|
+
if (!projectId) {
|
|
82
|
+
throw new Error('Missing PHRASE_PROJECT_ID');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return _callPhrase(`https://api.phrase.com/v2/projects/${projectId}/${relativePath}`, options).then(result => {
|
|
86
|
+
if (Array.isArray(result)) {
|
|
87
|
+
console.log('Result length:', result.length);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return result;
|
|
91
|
+
}).catch(error => {
|
|
92
|
+
console.error(`Error calling phrase for ${relativePath}:`, error);
|
|
93
|
+
throw Error;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function pullAllTranslations(branch) {
|
|
97
|
+
const phraseResult = await callPhrase(`translations?branch=${branch}&per_page=100`);
|
|
98
|
+
const translations = {};
|
|
99
|
+
|
|
100
|
+
for (const r of phraseResult) {
|
|
101
|
+
if (!translations[r.locale.code]) {
|
|
102
|
+
translations[r.locale.code] = {};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
translations[r.locale.code][r.key.name] = {
|
|
106
|
+
message: r.content
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return translations;
|
|
111
|
+
}
|
|
112
|
+
async function pushTranslationsByLocale(contents, locale, branch) {
|
|
113
|
+
const formData = new FormData__default['default']();
|
|
114
|
+
const fileContents = Buffer.from(JSON.stringify(contents));
|
|
115
|
+
formData.append('file', fileContents, {
|
|
116
|
+
contentType: 'application/json',
|
|
117
|
+
filename: `${locale}.json`
|
|
118
|
+
});
|
|
119
|
+
formData.append('file_format', 'json');
|
|
120
|
+
formData.append('locale_id', locale);
|
|
121
|
+
formData.append('branch', branch);
|
|
122
|
+
formData.append('update_translations', 'true');
|
|
123
|
+
trace('Starting to upload:', locale);
|
|
124
|
+
await callPhrase(`uploads`, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
body: formData
|
|
127
|
+
});
|
|
128
|
+
log('Successfully Uploaded:', locale, '\n');
|
|
129
|
+
}
|
|
130
|
+
async function ensureBranch(branch) {
|
|
131
|
+
await callPhrase(`branches`, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
headers: {
|
|
134
|
+
'Content-Type': 'application/json'
|
|
135
|
+
},
|
|
136
|
+
body: JSON.stringify({
|
|
137
|
+
name: branch
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
trace('Created branch:', branch);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function pull({
|
|
144
|
+
branch = 'local-development'
|
|
145
|
+
}, config) {
|
|
146
|
+
trace(`Pulling translations from branch ${branch}`);
|
|
147
|
+
await ensureBranch(branch);
|
|
148
|
+
const alternativeLanguages = core.getAltLanguages(config);
|
|
149
|
+
const allPhraseTranslations = await pullAllTranslations(branch);
|
|
150
|
+
trace(`Pulling translations from Phrase for languages ${config.devLanguage} and ${alternativeLanguages.join(', ')}`);
|
|
151
|
+
const phraseLanguages = Object.keys(allPhraseTranslations);
|
|
152
|
+
const phraseLanguagesWithTranslations = phraseLanguages.filter(language => {
|
|
153
|
+
const phraseTranslationsForLanguage = allPhraseTranslations[language];
|
|
154
|
+
return Object.keys(phraseTranslationsForLanguage).length > 0;
|
|
155
|
+
});
|
|
156
|
+
trace(`Found Phrase translations for languages ${phraseLanguagesWithTranslations.join(', ')}`);
|
|
157
|
+
|
|
158
|
+
if (!phraseLanguagesWithTranslations.includes(config.devLanguage)) {
|
|
159
|
+
throw new Error(`Phrase did not return any translations for dev language "${config.devLanguage}".\nEnsure you have configured your Phrase project for your dev language, and have pushed your translations.`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const allVocabTranslations = await core.loadAllTranslations({
|
|
163
|
+
fallbacks: 'none',
|
|
164
|
+
includeNodeModules: false
|
|
165
|
+
}, config);
|
|
166
|
+
|
|
167
|
+
for (const loadedTranslation of allVocabTranslations) {
|
|
168
|
+
const devTranslations = loadedTranslation.languages[config.devLanguage];
|
|
169
|
+
|
|
170
|
+
if (!devTranslations) {
|
|
171
|
+
throw new Error('No dev language translations loaded');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const defaultValues = { ...devTranslations
|
|
175
|
+
};
|
|
176
|
+
const localKeys = Object.keys(defaultValues);
|
|
177
|
+
|
|
178
|
+
for (const key of localKeys) {
|
|
179
|
+
defaultValues[key] = { ...defaultValues[key],
|
|
180
|
+
...allPhraseTranslations[config.devLanguage][core.getUniqueKey(key, loadedTranslation.namespace)]
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
await writeFile(loadedTranslation.filePath, `${JSON.stringify(defaultValues, null, 2)}\n`);
|
|
185
|
+
|
|
186
|
+
for (const alternativeLanguage of alternativeLanguages) {
|
|
187
|
+
if (alternativeLanguage in allPhraseTranslations) {
|
|
188
|
+
const altTranslations = { ...loadedTranslation.languages[alternativeLanguage]
|
|
189
|
+
};
|
|
190
|
+
const phraseAltTranslations = allPhraseTranslations[alternativeLanguage];
|
|
191
|
+
|
|
192
|
+
for (const key of localKeys) {
|
|
193
|
+
var _phraseAltTranslation;
|
|
194
|
+
|
|
195
|
+
const phraseKey = core.getUniqueKey(key, loadedTranslation.namespace);
|
|
196
|
+
const phraseTranslationMessage = (_phraseAltTranslation = phraseAltTranslations[phraseKey]) === null || _phraseAltTranslation === void 0 ? void 0 : _phraseAltTranslation.message;
|
|
197
|
+
|
|
198
|
+
if (!phraseTranslationMessage) {
|
|
199
|
+
trace(`Missing translation. No translation for key ${key} in phrase as ${phraseKey} in language ${alternativeLanguage}.`);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
altTranslations[key] = { ...altTranslations[key],
|
|
204
|
+
message: phraseTranslationMessage
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const altTranslationFilePath = core.getAltLanguageFilePath(loadedTranslation.filePath, alternativeLanguage);
|
|
209
|
+
await mkdir(path__default['default'].dirname(altTranslationFilePath), {
|
|
210
|
+
recursive: true
|
|
211
|
+
});
|
|
212
|
+
await writeFile(altTranslationFilePath, `${JSON.stringify(altTranslations, null, 2)}\n`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Uploading to the Phrase API for each language. Adding a unique namespace to each key using file path they key came from
|
|
220
|
+
*/
|
|
221
|
+
async function push({
|
|
222
|
+
branch
|
|
223
|
+
}, config) {
|
|
224
|
+
const allLanguageTranslations = await core.loadAllTranslations({
|
|
225
|
+
fallbacks: 'none',
|
|
226
|
+
includeNodeModules: false
|
|
227
|
+
}, config);
|
|
228
|
+
trace(`Pushing translations to branch ${branch}`);
|
|
229
|
+
const allLanguages = config.languages.map(v => v.name);
|
|
230
|
+
await ensureBranch(branch);
|
|
231
|
+
trace(`Pushing translations to phrase for languages ${allLanguages.join(', ')}`);
|
|
232
|
+
const phraseTranslations = {};
|
|
233
|
+
|
|
234
|
+
for (const loadedTranslation of allLanguageTranslations) {
|
|
235
|
+
for (const language of allLanguages) {
|
|
236
|
+
const localTranslations = loadedTranslation.languages[language];
|
|
237
|
+
|
|
238
|
+
if (!localTranslations) {
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!phraseTranslations[language]) {
|
|
243
|
+
phraseTranslations[language] = {};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
for (const localKey of Object.keys(localTranslations)) {
|
|
247
|
+
const phraseKey = core.getUniqueKey(localKey, loadedTranslation.namespace);
|
|
248
|
+
phraseTranslations[language][phraseKey] = localTranslations[localKey];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
for (const language of allLanguages) {
|
|
254
|
+
if (phraseTranslations[language]) {
|
|
255
|
+
await pushTranslationsByLocale(phraseTranslations[language], language, branch);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
exports.pull = pull;
|
|
261
|
+
exports.push = push;
|