poly-lexis 0.9.3 → 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/dist/index.d.ts CHANGED
@@ -218,6 +218,15 @@ interface OrphanedTranslation {
218
218
  language: string;
219
219
  value: string;
220
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
+ }
221
230
  interface UnusedTranslation {
222
231
  namespace: string;
223
232
  key: string;
@@ -229,6 +238,12 @@ interface ValidationResult {
229
238
  missing: MissingTranslation[];
230
239
  empty: MissingTranslation[];
231
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[];
232
247
  }
233
248
  interface UnusedKeysResult {
234
249
  unused: UnusedTranslation[];
@@ -282,6 +297,10 @@ interface AutoFillOptions {
282
297
  dryRun?: boolean;
283
298
  /** Number of concurrent translation requests (default: 5) */
284
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;
285
304
  }
286
305
  /**
287
306
  * Automatically fill empty or missing translations for a language
@@ -348,6 +367,10 @@ interface ManageTranslationsOptions {
348
367
  skipTypes?: boolean;
349
368
  /** Dry run mode */
350
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;
351
374
  }
352
375
  /**
353
376
  * Smart translation management - handles init, validation, auto-fill, and type generation
@@ -361,12 +384,39 @@ declare function manageTranslations(projectRoot?: string, options?: ManageTransl
361
384
  * Checks for missing keys, empty values, and orphaned keys (keys removed from source)
362
385
  */
363
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
+ }
364
392
  /**
365
- * 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).
366
396
  */
367
- declare function getMissingForLanguage(projectRoot: string, language: string): Array<MissingTranslation & {
368
- type: 'missing' | 'empty';
397
+ declare function getMissingForLanguage(projectRoot: string, language: string, options?: GetMissingOptions): Array<MissingTranslation & {
398
+ type: FillableType;
369
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;
370
420
 
371
421
  /**
372
422
  * Translation provider interface
@@ -447,6 +497,72 @@ declare class GoogleTranslateProvider implements TranslationProvider {
447
497
  validateConfig(): Promise<boolean>;
448
498
  }
449
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
+
450
566
  /**
451
567
  * Translation utilities with support for custom translation providers
452
568
  * Only translates content outside of {{variable}} interpolations
@@ -584,4 +700,4 @@ interface SyncResult {
584
700
  */
585
701
  declare function syncTranslationStructure(translationsPath: string, languages: string[], sourceLanguage: string): SyncResult;
586
702
 
587
- 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 };