@vocab/phrase 1.1.0 → 1.2.1

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,67 +0,0 @@
1
- import { TranslationsByLanguage } from './../../types/src/index';
2
-
3
- import {
4
- ensureBranch,
5
- pushTranslationsByLocale,
6
- deleteUnusedKeys as phraseDeleteUnusedKeys,
7
- } from './phrase-api';
8
- import { trace } from './logger';
9
- import { loadAllTranslations, getUniqueKey } from '@vocab/core';
10
- import { UserConfig } from '@vocab/types';
11
-
12
- interface PushOptions {
13
- branch: string;
14
- deleteUnusedKeys?: boolean;
15
- }
16
-
17
- /**
18
- * Uploading to the Phrase API for each language. Adding a unique namespace to each key using file path they key came from
19
- */
20
- export async function push(
21
- { branch, deleteUnusedKeys }: PushOptions,
22
- config: UserConfig,
23
- ) {
24
- const allLanguageTranslations = await loadAllTranslations(
25
- { fallbacks: 'none', includeNodeModules: false },
26
- config,
27
- );
28
- trace(`Pushing translations to branch ${branch}`);
29
- const allLanguages = config.languages.map((v) => v.name);
30
- await ensureBranch(branch);
31
-
32
- trace(
33
- `Pushing translations to phrase for languages ${allLanguages.join(', ')}`,
34
- );
35
-
36
- const phraseTranslations: TranslationsByLanguage = {};
37
-
38
- for (const loadedTranslation of allLanguageTranslations) {
39
- for (const language of allLanguages) {
40
- const localTranslations = loadedTranslation.languages[language];
41
- if (!localTranslations) {
42
- continue;
43
- }
44
- if (!phraseTranslations[language]) {
45
- phraseTranslations[language] = {};
46
- }
47
- for (const localKey of Object.keys(localTranslations)) {
48
- const phraseKey = getUniqueKey(localKey, loadedTranslation.namespace);
49
- phraseTranslations[language][phraseKey] = localTranslations[localKey];
50
- }
51
- }
52
- }
53
-
54
- for (const language of allLanguages) {
55
- if (phraseTranslations[language]) {
56
- const { uploadId } = await pushTranslationsByLocale(
57
- phraseTranslations[language],
58
- language,
59
- branch,
60
- );
61
-
62
- if (deleteUnusedKeys) {
63
- await phraseDeleteUnusedKeys(uploadId, language, branch);
64
- }
65
- }
66
- }
67
- }