@vocab/core 1.1.2 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ ### MIT License
2
+
3
+ Copyright (c) 2020 SEEK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -422,20 +422,81 @@ Or to re-run the compiler when files change use:
422
422
  $ vocab compile --watch
423
423
  ```
424
424
 
425
- ## External translation tooling
425
+ ## External Translation Tooling
426
426
 
427
427
  Vocab can be used to synchronize your translations with translations from a remote translation platform.
428
428
 
429
- | Platform | Environment Variables |
430
- | -------------------------------------------- | ----------------------------------- |
431
- | [Phrase](https://developers.phrase.com/api/) | PHRASE_PROJECT_ID, PHRASE_API_TOKEN |
429
+ | Platform | Environment Variables |
430
+ | -------- | ----------------------------------- |
431
+ | [Phrase] | PHRASE_PROJECT_ID, PHRASE_API_TOKEN |
432
432
 
433
433
  ```bash
434
434
  $ vocab push --branch my-branch
435
- $ vocab push --branch my-branch --delete-unused-keys
436
435
  $ vocab pull --branch my-branch
437
436
  ```
438
437
 
438
+ ### [Phrase] Platform Features
439
+
440
+ #### Delete Unused keys
441
+
442
+ When uploading translations, Phrase identifies keys that exist in the Phrase project, but were not
443
+ referenced in the upload. These keys can be deleted from Phrase by providing the
444
+ `---delete-unused-keys` flag to `vocab push`. E.g.
445
+
446
+ ```sh
447
+ $ vocab push --branch my-branch --delete-unused-keys
448
+ ```
449
+
450
+ [phrase]: https://developers.phrase.com/api/
451
+
452
+ #### [Tags]
453
+
454
+ `vocab push` supports uploading [tags] to Phrase.
455
+
456
+ Tags can be added to an individual key via the `tags` property:
457
+
458
+ ```jsonc
459
+ // translations.json
460
+ {
461
+ "Hello": {
462
+ "message": "Hello",
463
+ "tags": ["greeting", "home_page"]
464
+ },
465
+ "Goodbye": {
466
+ "message": "Goodbye",
467
+ "tags": ["home_page"]
468
+ }
469
+ }
470
+ ```
471
+
472
+ Tags can also be added under a top-level `_meta` field. This will result in the tags applying to all
473
+ keys specified in the file:
474
+
475
+ ```jsonc
476
+ // translations.json
477
+ {
478
+ "_meta": {
479
+ "tags": ["home_page"]
480
+ },
481
+ "Hello": {
482
+ "message": "Hello",
483
+ "tags": ["greeting"]
484
+ },
485
+ "Goodbye": {
486
+ "message": "Goodbye"
487
+ }
488
+ }
489
+ ```
490
+
491
+ In the above example, both the `Hello` and `Goodbye` keys would have the `home_page` tag attached to
492
+ them, but only the `Hello` key would have the `usage_greeting` tag attached to it.
493
+
494
+ **NOTE**: Only tags specified on keys in your [`devLanguage`][configuration] will be uploaded.
495
+ Tags on keys in other languages will be ignored.
496
+
497
+ [tags]: https://support.phrase.com/hc/en-us/articles/5822598372252-Tags-Strings-
498
+ [configuration]: #Configuration
499
+
439
500
  ## Troubleshooting
440
501
 
441
502
  ### Problem: Passed locale is being ignored or using en-US instead
@@ -1,5 +1,5 @@
1
- export declare class ValidationError extends Error {
2
- code: string;
3
- rawMessage: string;
4
- constructor(code: string, message: string);
5
- }
1
+ export declare class ValidationError extends Error {
2
+ code: string;
3
+ rawMessage: string;
4
+ constructor(code: string, message: string);
5
+ }
@@ -1,6 +1,6 @@
1
- import { LoadedTranslation, UserConfig } from '@vocab/types';
2
- export declare function generateRuntime(loadedTranslation: LoadedTranslation): Promise<void>;
3
- export declare function watch(config: UserConfig): () => Promise<void>;
4
- export declare function compile({ watch: shouldWatch }: {
5
- watch?: boolean | undefined;
6
- } | undefined, config: UserConfig): Promise<(() => Promise<void>) | undefined>;
1
+ import { LoadedTranslation, UserConfig } from '@vocab/types';
2
+ export declare function generateRuntime(loadedTranslation: LoadedTranslation): Promise<void>;
3
+ export declare function watch(config: UserConfig): () => Promise<void>;
4
+ export declare function compile({ watch: shouldWatch }: {
5
+ watch?: boolean | undefined;
6
+ } | undefined, config: UserConfig): Promise<(() => Promise<void>) | undefined>;
@@ -1,4 +1,4 @@
1
- import { UserConfig } from '@vocab/types';
2
- export declare function validateConfig(c: UserConfig): boolean;
3
- export declare function resolveConfig(customConfigFilePath?: string): Promise<UserConfig | null>;
4
- export declare function resolveConfigSync(customConfigFilePath?: string): UserConfig | null;
1
+ import { UserConfig } from '@vocab/types';
2
+ export declare function validateConfig(c: UserConfig): boolean;
3
+ export declare function resolveConfig(customConfigFilePath?: string): Promise<UserConfig | null>;
4
+ export declare function resolveConfigSync(customConfigFilePath?: string): UserConfig | null;
@@ -1,5 +1,5 @@
1
- import { MessageGenerator, TranslationsByKey } from '@vocab/types';
2
- export declare function generateLanguageFromTranslations({ baseTranslations, generator, }: {
3
- baseTranslations: TranslationsByKey<string>;
4
- generator: MessageGenerator;
5
- }): TranslationsByKey<string>;
1
+ import { MessageGenerator, TranslationsByKey } from '@vocab/types';
2
+ export declare function generateLanguageFromTranslations({ baseTranslations, generator, }: {
3
+ baseTranslations: TranslationsByKey<string>;
4
+ generator: MessageGenerator;
5
+ }): TranslationsByKey<string>;
@@ -1,2 +1,2 @@
1
- import { ParsedICUMessages, TranslationMessagesByKey } from '@vocab/types';
2
- export declare const getParsedICUMessages: (m: TranslationMessagesByKey, locale: string) => ParsedICUMessages<any>;
1
+ import { ParsedICUMessages, TranslationMessagesByKey } from '@vocab/types';
2
+ export declare const getParsedICUMessages: (m: TranslationMessagesByKey, locale: string) => ParsedICUMessages<any>;
@@ -1,6 +1,6 @@
1
- export { compile, watch } from './compile';
2
- export { validate } from './validate';
3
- export { resolveConfig, resolveConfigSync, validateConfig } from './config';
4
- export { getAltLanguages, getAltLanguageFilePath, getDevLanguageFileFromTsFile, } from './utils';
5
- export { getUniqueKey, loadAllTranslations, loadTranslation, } from './load-translations';
6
- export type { TranslationFile } from '@vocab/types';
1
+ export { compile, watch } from './compile';
2
+ export { validate } from './validate';
3
+ export { resolveConfig, resolveConfigSync, validateConfig } from './config';
4
+ export { getAltLanguages, getAltLanguageFilePath, getDevLanguageFileFromTsFile, } from './utils';
5
+ export { getUniqueKey, loadAllTranslations, loadTranslation, } from './load-translations';
6
+ export type { TranslationFile } from '@vocab/types';
@@ -1,30 +1,32 @@
1
- import { TranslationsByKey, UserConfig, LoadedTranslation, LanguageTarget } from '@vocab/types';
2
- import { Fallback } from './utils';
3
- export declare function getUniqueKey(key: string, namespace: string): string;
4
- export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
5
- translation: TranslationsByKey;
6
- devTranslation: TranslationsByKey;
7
- }): TranslationsByKey<string>;
8
- export declare function getLanguageHierarchy({ languages, }: {
9
- languages: Array<LanguageTarget>;
10
- }): Map<string, string[]>;
11
- export declare function getFallbackLanguageOrder({ languages, languageName, devLanguage, fallbacks, }: {
12
- languages: LanguageTarget[];
13
- languageName: string;
14
- devLanguage: string;
15
- fallbacks: Fallback;
16
- }): string[];
17
- export declare function loadAltLanguageFile({ filePath, languageName, devTranslation, fallbacks, }: {
18
- filePath: string;
19
- languageName: string;
20
- devTranslation: TranslationsByKey;
21
- fallbacks: Fallback;
22
- }, { devLanguage, languages }: UserConfig): TranslationsByKey;
23
- export declare function loadTranslation({ filePath, fallbacks, }: {
24
- filePath: string;
25
- fallbacks: Fallback;
26
- }, userConfig: UserConfig): LoadedTranslation;
27
- export declare function loadAllTranslations({ fallbacks, includeNodeModules, }: {
28
- fallbacks: Fallback;
29
- includeNodeModules: boolean;
30
- }, config: UserConfig): Promise<Array<LoadedTranslation>>;
1
+ import type { TranslationsByKey, UserConfig, LoadedTranslation, LanguageTarget } from '@vocab/types';
2
+ import { Fallback } from './utils';
3
+ export declare function getUniqueKey(key: string, namespace: string): string;
4
+ export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
5
+ translation: TranslationsByKey;
6
+ devTranslation: TranslationsByKey;
7
+ }): TranslationsByKey<string>;
8
+ export declare function getLanguageHierarchy({ languages, }: {
9
+ languages: Array<LanguageTarget>;
10
+ }): Map<string, string[]>;
11
+ export declare function getFallbackLanguageOrder({ languages, languageName, devLanguage, fallbacks, }: {
12
+ languages: LanguageTarget[];
13
+ languageName: string;
14
+ devLanguage: string;
15
+ fallbacks: Fallback;
16
+ }): string[];
17
+ export declare function loadAltLanguageFile({ filePath, languageName, devTranslation, fallbacks, }: {
18
+ filePath: string;
19
+ languageName: string;
20
+ devTranslation: TranslationsByKey;
21
+ fallbacks: Fallback;
22
+ }, { devLanguage, languages }: UserConfig): TranslationsByKey;
23
+ export declare function loadTranslation({ filePath, fallbacks, withTags, }: {
24
+ filePath: string;
25
+ fallbacks: Fallback;
26
+ withTags?: boolean;
27
+ }, userConfig: UserConfig): LoadedTranslation;
28
+ export declare function loadAllTranslations({ fallbacks, includeNodeModules, withTags, }: {
29
+ fallbacks: Fallback;
30
+ includeNodeModules: boolean;
31
+ withTags?: boolean;
32
+ }, config: UserConfig): Promise<Array<LoadedTranslation>>;
@@ -1,3 +1,3 @@
1
- import debug from 'debug';
2
- export declare const trace: debug.Debugger;
3
- export declare const log: (...params: unknown[]) => void;
1
+ import debug from 'debug';
2
+ export declare const trace: debug.Debugger;
3
+ export declare const log: (...params: unknown[]) => void;
@@ -1,3 +1,3 @@
1
- import { TranslationModule, TranslationMessagesByKey } from '@vocab/types';
2
- export { createTranslationFile } from './translation-file';
3
- export declare const createLanguage: (module: TranslationMessagesByKey) => TranslationModule<any>;
1
+ import { TranslationModule, TranslationMessagesByKey } from '@vocab/types';
2
+ export { createTranslationFile } from './translation-file';
3
+ export declare const createLanguage: (module: TranslationMessagesByKey) => TranslationModule<any>;
@@ -1,2 +1,2 @@
1
- import { TranslationModuleByLanguage, LanguageName, ParsedFormatFnByKey, TranslationFile } from '@vocab/types';
2
- export declare function createTranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey>(translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>): TranslationFile<Language, FormatFnByKey>;
1
+ import { TranslationModuleByLanguage, LanguageName, ParsedFormatFnByKey, TranslationFile } from '@vocab/types';
2
+ export declare function createTranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey>(translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>): TranslationFile<Language, FormatFnByKey>;
@@ -1,26 +1,26 @@
1
- import type { LanguageName, LanguageTarget, TranslationsByKey, TranslationMessagesByKey, UserConfig } from '@vocab/types';
2
- export declare const defaultTranslationDirSuffix = ".vocab";
3
- export declare const devTranslationFileName = "translations.json";
4
- export declare type Fallback = 'none' | 'valid' | 'all';
5
- export declare function isDevLanguageFile(filePath: string): boolean;
6
- export declare function isAltLanguageFile(filePath: string): boolean;
7
- export declare function isTranslationDirectory(filePath: string, { translationsDirectorySuffix, }: {
8
- translationsDirectorySuffix?: string;
9
- }): boolean;
10
- export declare function getTranslationFolderGlob({ translationsDirectorySuffix, }: {
11
- translationsDirectorySuffix?: string;
12
- }): string;
13
- export declare function getDevTranslationFileGlob({ translationsDirectorySuffix, }: {
14
- translationsDirectorySuffix?: string;
15
- }): string;
16
- export declare function getAltTranslationFileGlob(config: UserConfig): string;
17
- export declare function getAltLanguages({ devLanguage, languages, }: {
18
- devLanguage: LanguageName;
19
- languages: Array<LanguageTarget>;
20
- }): string[];
21
- export declare function getDevLanguageFileFromTsFile(tsFilePath: string): string;
22
- export declare function getDevLanguageFileFromAltLanguageFile(altLanguageFilePath: string): string;
23
- export declare function getTSFileFromDevLanguageFile(devLanguageFilePath: string): string;
24
- export declare function getAltLanguageFilePath(devLanguageFilePath: string, language: string): string;
25
- export declare function mapValues<Key extends string, OriginalValue, ReturnValue>(obj: Record<Key, OriginalValue>, func: (val: OriginalValue) => ReturnValue): TranslationMessagesByKey<Key>;
26
- export declare function getTranslationMessages<Key extends string>(translations: TranslationsByKey<Key>): TranslationMessagesByKey<Key>;
1
+ import type { LanguageName, LanguageTarget, TranslationsByKey, TranslationMessagesByKey, UserConfig } from '@vocab/types';
2
+ export declare const defaultTranslationDirSuffix = ".vocab";
3
+ export declare const devTranslationFileName = "translations.json";
4
+ export type Fallback = 'none' | 'valid' | 'all';
5
+ export declare function isDevLanguageFile(filePath: string): boolean;
6
+ export declare function isAltLanguageFile(filePath: string): boolean;
7
+ export declare function isTranslationDirectory(filePath: string, { translationsDirectorySuffix, }: {
8
+ translationsDirectorySuffix?: string;
9
+ }): boolean;
10
+ export declare function getTranslationFolderGlob({ translationsDirectorySuffix, }: {
11
+ translationsDirectorySuffix?: string;
12
+ }): string;
13
+ export declare function getDevTranslationFileGlob({ translationsDirectorySuffix, }: {
14
+ translationsDirectorySuffix?: string;
15
+ }): string;
16
+ export declare function getAltTranslationFileGlob(config: UserConfig): string;
17
+ export declare function getAltLanguages({ devLanguage, languages, }: {
18
+ devLanguage: LanguageName;
19
+ languages: Array<LanguageTarget>;
20
+ }): string[];
21
+ export declare function getDevLanguageFileFromTsFile(tsFilePath: string): string;
22
+ export declare function getDevLanguageFileFromAltLanguageFile(altLanguageFilePath: string): string;
23
+ export declare function getTSFileFromDevLanguageFile(devLanguageFilePath: string): string;
24
+ export declare function getAltLanguageFilePath(devLanguageFilePath: string, language: string): string;
25
+ export declare function mapValues<Key extends string, OriginalValue, ReturnValue>(obj: Record<Key, OriginalValue>, func: (val: OriginalValue) => ReturnValue): TranslationMessagesByKey<Key>;
26
+ export declare function getTranslationMessages<Key extends string>(translations: TranslationsByKey<Key>): TranslationMessagesByKey<Key>;
@@ -1,3 +1,3 @@
1
- import { UserConfig, LoadedTranslation, LanguageName } from '@vocab/types';
2
- export declare function findMissingKeys(loadedTranslation: LoadedTranslation, devLanguageName: LanguageName, altLanguages: Array<LanguageName>): readonly [boolean, Record<string, string[]>];
3
- export declare function validate(config: UserConfig): Promise<boolean>;
1
+ import { UserConfig, LoadedTranslation, LanguageName } from '@vocab/types';
2
+ export declare function findMissingKeys(loadedTranslation: LoadedTranslation, devLanguageName: LanguageName, altLanguages: Array<LanguageName>): readonly [boolean, Record<string, string[]>];
3
+ export declare function validate(config: UserConfig): Promise<boolean>;