poly-lexis 0.9.2 → 0.11.0
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/README.md +33 -0
- package/dist/cli/translations.js +382 -108
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +128 -4
- package/dist/index.js +365 -93
- package/dist/index.js.map +1 -1
- package/dist/scripts/generate-schema.js +8 -0
- package/dist/scripts/generate-schema.js.map +1 -1
- package/dist/scripts/verify-translations.js +147 -37
- package/dist/scripts/verify-translations.js.map +1 -1
- package/dist/translations/core/translations-config.schema.json +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,14 @@ declare const TRANSLATION_CONFIG_SCHEMA: {
|
|
|
128
128
|
};
|
|
129
129
|
default: string[];
|
|
130
130
|
};
|
|
131
|
+
protectedTerms: {
|
|
132
|
+
type: string;
|
|
133
|
+
description: string;
|
|
134
|
+
items: {
|
|
135
|
+
type: string;
|
|
136
|
+
};
|
|
137
|
+
default: never[];
|
|
138
|
+
};
|
|
131
139
|
};
|
|
132
140
|
required: string[];
|
|
133
141
|
additionalProperties: boolean;
|
|
@@ -210,6 +218,15 @@ interface OrphanedTranslation {
|
|
|
210
218
|
language: string;
|
|
211
219
|
value: string;
|
|
212
220
|
}
|
|
221
|
+
interface StaleTranslation {
|
|
222
|
+
namespace: string;
|
|
223
|
+
key: string;
|
|
224
|
+
language: string;
|
|
225
|
+
/** Current source value (the translation should be regenerated from this) */
|
|
226
|
+
sourceValue: string;
|
|
227
|
+
/** The existing, potentially outdated, translated value */
|
|
228
|
+
currentValue: string;
|
|
229
|
+
}
|
|
213
230
|
interface UnusedTranslation {
|
|
214
231
|
namespace: string;
|
|
215
232
|
key: string;
|
|
@@ -221,6 +238,12 @@ interface ValidationResult {
|
|
|
221
238
|
missing: MissingTranslation[];
|
|
222
239
|
empty: MissingTranslation[];
|
|
223
240
|
orphaned: OrphanedTranslation[];
|
|
241
|
+
/**
|
|
242
|
+
* Translations whose source value has changed since they were generated.
|
|
243
|
+
* Only detectable for translations written with source-hash tracking enabled.
|
|
244
|
+
* Reported as a warning; does not affect `valid`.
|
|
245
|
+
*/
|
|
246
|
+
stale: StaleTranslation[];
|
|
224
247
|
}
|
|
225
248
|
interface UnusedKeysResult {
|
|
226
249
|
unused: UnusedTranslation[];
|
|
@@ -274,6 +297,10 @@ interface AutoFillOptions {
|
|
|
274
297
|
dryRun?: boolean;
|
|
275
298
|
/** Number of concurrent translation requests (default: 5) */
|
|
276
299
|
concurrency?: number;
|
|
300
|
+
/** Re-translate keys whose source value has changed since they were written */
|
|
301
|
+
retranslateChanged?: boolean;
|
|
302
|
+
/** Re-translate every key, even ones that already have an up-to-date value */
|
|
303
|
+
force?: boolean;
|
|
277
304
|
}
|
|
278
305
|
/**
|
|
279
306
|
* Automatically fill empty or missing translations for a language
|
|
@@ -340,6 +367,10 @@ interface ManageTranslationsOptions {
|
|
|
340
367
|
skipTypes?: boolean;
|
|
341
368
|
/** Dry run mode */
|
|
342
369
|
dryRun?: boolean;
|
|
370
|
+
/** Re-translate keys whose source value has changed (stale translations) */
|
|
371
|
+
retranslateChanged?: boolean;
|
|
372
|
+
/** Re-translate every key, regardless of current value */
|
|
373
|
+
force?: boolean;
|
|
343
374
|
}
|
|
344
375
|
/**
|
|
345
376
|
* Smart translation management - handles init, validation, auto-fill, and type generation
|
|
@@ -353,12 +384,39 @@ declare function manageTranslations(projectRoot?: string, options?: ManageTransl
|
|
|
353
384
|
* Checks for missing keys, empty values, and orphaned keys (keys removed from source)
|
|
354
385
|
*/
|
|
355
386
|
declare function validateTranslations(projectRoot?: string): ValidationResult;
|
|
387
|
+
type FillableType = 'missing' | 'empty' | 'stale';
|
|
388
|
+
interface GetMissingOptions {
|
|
389
|
+
/** Also include translations whose source value has changed (stale) */
|
|
390
|
+
includeStale?: boolean;
|
|
391
|
+
}
|
|
356
392
|
/**
|
|
357
|
-
* Get all missing or empty translations for a specific language
|
|
393
|
+
* Get all missing or empty translations for a specific language.
|
|
394
|
+
* When `includeStale` is set, also returns translations whose source value has
|
|
395
|
+
* changed since they were written (so they can be re-translated).
|
|
358
396
|
*/
|
|
359
|
-
declare function getMissingForLanguage(projectRoot: string, language: string): Array<MissingTranslation & {
|
|
360
|
-
type:
|
|
397
|
+
declare function getMissingForLanguage(projectRoot: string, language: string, options?: GetMissingOptions): Array<MissingTranslation & {
|
|
398
|
+
type: FillableType;
|
|
361
399
|
}>;
|
|
400
|
+
interface BaselineResult {
|
|
401
|
+
/** Number of existing translations newly recorded against their current source value */
|
|
402
|
+
recorded: number;
|
|
403
|
+
/** Whether the metadata sidecar file was created by this call */
|
|
404
|
+
created: boolean;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Establish a change-tracking baseline for an existing translation set.
|
|
408
|
+
*
|
|
409
|
+
* For every key that already has a non-empty translation but no recorded source
|
|
410
|
+
* hash, record the hash of its *current* source value. This lets existing
|
|
411
|
+
* codebases (whose translations predate change tracking) start detecting future
|
|
412
|
+
* source changes without re-translating anything.
|
|
413
|
+
*
|
|
414
|
+
* Keys that already have a recorded hash are left untouched — overwriting them
|
|
415
|
+
* would erase the signal that a translation has gone stale. As a result, this
|
|
416
|
+
* treats whatever is currently in the repo as the up-to-date baseline: a
|
|
417
|
+
* translation that is already stale at adoption time will be accepted as current.
|
|
418
|
+
*/
|
|
419
|
+
declare function ensureBaselineMetadata(projectRoot?: string): BaselineResult;
|
|
362
420
|
|
|
363
421
|
/**
|
|
364
422
|
* Translation provider interface
|
|
@@ -439,6 +497,72 @@ declare class GoogleTranslateProvider implements TranslationProvider {
|
|
|
439
497
|
validateConfig(): Promise<boolean>;
|
|
440
498
|
}
|
|
441
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Name of the sidecar file (stored at the root of the translations directory)
|
|
502
|
+
* that records a hash of the source value each translation was generated from.
|
|
503
|
+
* This lets us detect when a source string has changed since its translations
|
|
504
|
+
* were written, so we can flag stale translations and optionally re-translate them.
|
|
505
|
+
*/
|
|
506
|
+
declare const METADATA_FILE_NAME = ".translations-meta.json";
|
|
507
|
+
/**
|
|
508
|
+
* Per-language map of namespace -> key -> source value hash.
|
|
509
|
+
*/
|
|
510
|
+
interface TranslationMetadata {
|
|
511
|
+
/** Schema version, for forward compatibility */
|
|
512
|
+
version: number;
|
|
513
|
+
/** language -> namespace -> key -> hash of the source value at translation time */
|
|
514
|
+
languages: {
|
|
515
|
+
[language: string]: {
|
|
516
|
+
[namespace: string]: {
|
|
517
|
+
[key: string]: string;
|
|
518
|
+
};
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Create an empty metadata structure
|
|
524
|
+
*/
|
|
525
|
+
declare function emptyMetadata(): TranslationMetadata;
|
|
526
|
+
/**
|
|
527
|
+
* Compute a stable hash of a source value. Used to detect changes to source
|
|
528
|
+
* strings after their translations have been generated.
|
|
529
|
+
*/
|
|
530
|
+
declare function hashSourceValue(value: string): string;
|
|
531
|
+
/**
|
|
532
|
+
* Absolute path to the metadata sidecar file
|
|
533
|
+
*/
|
|
534
|
+
declare function getMetadataPath(translationsPath: string): string;
|
|
535
|
+
/**
|
|
536
|
+
* Whether a metadata sidecar file exists for this translations directory
|
|
537
|
+
*/
|
|
538
|
+
declare function metadataExists(translationsPath: string): boolean;
|
|
539
|
+
/**
|
|
540
|
+
* Read the metadata sidecar file. Returns an empty structure if it does not
|
|
541
|
+
* exist or cannot be parsed.
|
|
542
|
+
*/
|
|
543
|
+
declare function readMetadata(translationsPath: string): TranslationMetadata;
|
|
544
|
+
/**
|
|
545
|
+
* Write the metadata sidecar file
|
|
546
|
+
*/
|
|
547
|
+
declare function writeMetadata(translationsPath: string, metadata: TranslationMetadata): void;
|
|
548
|
+
/**
|
|
549
|
+
* Record (in memory) the source value a translation was generated from.
|
|
550
|
+
* Mutates and returns the provided metadata object so callers can batch many
|
|
551
|
+
* updates before a single {@link writeMetadata} call.
|
|
552
|
+
*/
|
|
553
|
+
declare function setSourceHash(metadata: TranslationMetadata, language: string, namespace: string, key: string, sourceValue: string): TranslationMetadata;
|
|
554
|
+
/**
|
|
555
|
+
* Get the stored source value hash for a translation, or undefined if none was
|
|
556
|
+
* recorded (e.g. for translations written before tracking was enabled).
|
|
557
|
+
*/
|
|
558
|
+
declare function getSourceHash(metadata: TranslationMetadata, language: string, namespace: string, key: string): string | undefined;
|
|
559
|
+
/**
|
|
560
|
+
* Remove any recorded hashes that no longer correspond to a key present in the
|
|
561
|
+
* source translations. `sourceKeysByNamespace` maps each source namespace to the
|
|
562
|
+
* set of keys it currently contains. Returns true if anything was pruned.
|
|
563
|
+
*/
|
|
564
|
+
declare function pruneMetadata(metadata: TranslationMetadata, sourceKeysByNamespace: Record<string, Set<string>>): boolean;
|
|
565
|
+
|
|
442
566
|
/**
|
|
443
567
|
* Translation utilities with support for custom translation providers
|
|
444
568
|
* Only translates content outside of {{variable}} interpolations
|
|
@@ -576,4 +700,4 @@ interface SyncResult {
|
|
|
576
700
|
*/
|
|
577
701
|
declare function syncTranslationStructure(translationsPath: string, languages: string[], sourceLanguage: string): SyncResult;
|
|
578
702
|
|
|
579
|
-
export { DEEPL_LANGUAGES, DEFAULT_CONFIG, DEFAULT_LANGUAGES, type DeepLLanguage, type DuplicateKeysResult, type DuplicateTranslation, GOOGLE_LANGUAGES, type GoogleLanguage, GoogleTranslateProvider, type LanguageFallbackResult, type ManageTranslationsOptions, type MissingTranslation, type NestedTranslationFile, type OrphanedTranslation, SUPPORTED_LANGUAGES, type SupportedLanguage, type SyncResult, TRANSLATION_CONFIG_SCHEMA, TRANSLATION_PROVIDERS, type TranslateOptions, type TranslationConfig, type TranslationEntry, type TranslationFile, type TranslationFiles, type TranslationProvider, type TranslationProviderFactory, type TranslationProviderType, type TranslationResult, type UnusedKeysResult, type UnusedTranslation, type ValidationResult, addTranslationKey, addTranslationKeys, autoFillTranslations, createEmptyTranslationStructure, detectExistingTranslations, ensureTranslationsStructure, extractPluralBaseKeys, extractVariables, fillNamespace, findUnusedKeys, flattenObject, generateTranslationTypes, getAvailableLanguages, getFallbackMappings, getMissingForLanguage, getNamespaces, getSupportedLanguages, getTranslationProvider, hasInterpolation, initTranslations, initTranslationsInteractive, isNestedObject, isValidDeepLLanguage, isValidGoogleLanguage, isValidLanguage, isValidLanguageForProvider, loadConfig, logLanguageFallback, manageTranslations, printUnusedKeysResult, readTranslations, resetTranslationProvider, resolveLanguageWithFallback, setTranslationProvider, sortKeys, syncTranslationStructure, translateBatch, translateText, unflattenObject, validateLanguages, validateLanguagesForProvider, validateTranslations, validateVariables, writeTranslation };
|
|
703
|
+
export { type BaselineResult, DEEPL_LANGUAGES, DEFAULT_CONFIG, DEFAULT_LANGUAGES, type DeepLLanguage, type DuplicateKeysResult, type DuplicateTranslation, type FillableType, GOOGLE_LANGUAGES, type GetMissingOptions, type GoogleLanguage, GoogleTranslateProvider, type LanguageFallbackResult, METADATA_FILE_NAME, type ManageTranslationsOptions, type MissingTranslation, type NestedTranslationFile, type OrphanedTranslation, SUPPORTED_LANGUAGES, type StaleTranslation, type SupportedLanguage, type SyncResult, TRANSLATION_CONFIG_SCHEMA, TRANSLATION_PROVIDERS, type TranslateOptions, type TranslationConfig, type TranslationEntry, type TranslationFile, type TranslationFiles, type TranslationMetadata, type TranslationProvider, type TranslationProviderFactory, type TranslationProviderType, type TranslationResult, type UnusedKeysResult, type UnusedTranslation, type ValidationResult, addTranslationKey, addTranslationKeys, autoFillTranslations, createEmptyTranslationStructure, detectExistingTranslations, emptyMetadata, ensureBaselineMetadata, ensureTranslationsStructure, extractPluralBaseKeys, extractVariables, fillNamespace, findUnusedKeys, flattenObject, generateTranslationTypes, getAvailableLanguages, getFallbackMappings, getMetadataPath, getMissingForLanguage, getNamespaces, getSourceHash, getSupportedLanguages, getTranslationProvider, hasInterpolation, hashSourceValue, initTranslations, initTranslationsInteractive, isNestedObject, isValidDeepLLanguage, isValidGoogleLanguage, isValidLanguage, isValidLanguageForProvider, loadConfig, logLanguageFallback, manageTranslations, metadataExists, printUnusedKeysResult, pruneMetadata, readMetadata, readTranslations, resetTranslationProvider, resolveLanguageWithFallback, setSourceHash, setTranslationProvider, sortKeys, syncTranslationStructure, translateBatch, translateText, unflattenObject, validateLanguages, validateLanguagesForProvider, validateTranslations, validateVariables, writeMetadata, writeTranslation };
|