poly-lexis 0.6.0 → 0.8.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/cli/translations.js +141 -10
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/scripts/verify-translations.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -225,6 +225,16 @@ interface UnusedKeysResult {
|
|
|
225
225
|
totalKeys: number;
|
|
226
226
|
searchedFiles: number;
|
|
227
227
|
}
|
|
228
|
+
interface DuplicateTranslation {
|
|
229
|
+
namespace: string;
|
|
230
|
+
key: string;
|
|
231
|
+
commonKey: string;
|
|
232
|
+
value: string;
|
|
233
|
+
}
|
|
234
|
+
interface DuplicateKeysResult {
|
|
235
|
+
duplicates: DuplicateTranslation[];
|
|
236
|
+
totalKeysChecked: number;
|
|
237
|
+
}
|
|
228
238
|
declare const DEFAULT_CONFIG: Required<TranslationConfig>;
|
|
229
239
|
declare const DEFAULT_LANGUAGES: readonly ["en", "fr", "it", "pl", "es", "pt", "de", "nl", "sv", "hu", "cs", "ja"];
|
|
230
240
|
|
|
@@ -282,6 +292,11 @@ declare function findUnusedKeys(projectRoot?: string): UnusedKeysResult;
|
|
|
282
292
|
*/
|
|
283
293
|
declare function printUnusedKeysResult(result: UnusedKeysResult): void;
|
|
284
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Extract base keys from plural-suffixed keys (e.g., "items_one" -> "items")
|
|
297
|
+
* Follows CLDR plural categories used by i18next and similar libraries.
|
|
298
|
+
*/
|
|
299
|
+
declare function extractPluralBaseKeys(keys: string[]): string[];
|
|
285
300
|
/**
|
|
286
301
|
* Generate TypeScript types from translation files
|
|
287
302
|
*/
|
|
@@ -557,4 +572,4 @@ interface SyncResult {
|
|
|
557
572
|
*/
|
|
558
573
|
declare function syncTranslationStructure(translationsPath: string, languages: string[], sourceLanguage: string): SyncResult;
|
|
559
574
|
|
|
560
|
-
export { DEEPL_LANGUAGES, DEFAULT_CONFIG, DEFAULT_LANGUAGES, type DeepLLanguage, 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, 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 };
|
|
575
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1195,6 +1195,23 @@ init_init();
|
|
|
1195
1195
|
import { execSync } from "child_process";
|
|
1196
1196
|
import * as fs3 from "fs";
|
|
1197
1197
|
import * as path3 from "path";
|
|
1198
|
+
var PLURAL_SUFFIXES = ["_zero", "_one", "_two", "_few", "_many", "_other"];
|
|
1199
|
+
function extractPluralBaseKeys(keys) {
|
|
1200
|
+
const keySet = new Set(keys);
|
|
1201
|
+
const baseKeys = /* @__PURE__ */ new Set();
|
|
1202
|
+
for (const key of keys) {
|
|
1203
|
+
for (const suffix of PLURAL_SUFFIXES) {
|
|
1204
|
+
if (key.endsWith(suffix)) {
|
|
1205
|
+
const baseKey = key.slice(0, -suffix.length);
|
|
1206
|
+
if (baseKey && !keySet.has(baseKey)) {
|
|
1207
|
+
baseKeys.add(baseKey);
|
|
1208
|
+
}
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return Array.from(baseKeys);
|
|
1214
|
+
}
|
|
1198
1215
|
var typeTemplate = (translationKeys, namespaceKeys) => `
|
|
1199
1216
|
export const translationKeys = [${translationKeys.map((key) => `"${key}"`).join(", ")}] as const;
|
|
1200
1217
|
export const namespaceKeys = [${namespaceKeys.map((key) => `"${key}"`).join(", ")}] as const;
|
|
@@ -1225,6 +1242,8 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
1225
1242
|
const keys = Object.keys(translations[namespace] || {});
|
|
1226
1243
|
allKeys = allKeys.concat(keys);
|
|
1227
1244
|
}
|
|
1245
|
+
const pluralBaseKeys = extractPluralBaseKeys(allKeys);
|
|
1246
|
+
allKeys = allKeys.concat(pluralBaseKeys);
|
|
1228
1247
|
const outputDir = path3.dirname(outputFilePath);
|
|
1229
1248
|
if (!fs3.existsSync(outputDir)) {
|
|
1230
1249
|
fs3.mkdirSync(outputDir, { recursive: true });
|
|
@@ -2214,6 +2233,7 @@ export {
|
|
|
2214
2233
|
createEmptyTranslationStructure,
|
|
2215
2234
|
detectExistingTranslations,
|
|
2216
2235
|
ensureTranslationsStructure,
|
|
2236
|
+
extractPluralBaseKeys,
|
|
2217
2237
|
extractVariables,
|
|
2218
2238
|
fillNamespace,
|
|
2219
2239
|
findUnusedKeys,
|