poly-lexis 0.6.0 → 0.8.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/dist/cli/translations.js +145 -12
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +24 -2
- 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,12 +1195,31 @@ 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
|
|
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
|
+
}
|
|
1215
|
+
var typeTemplate = (translationKeys, namespaceKeys, languages) => `
|
|
1199
1216
|
export const translationKeys = [${translationKeys.map((key) => `"${key}"`).join(", ")}] as const;
|
|
1200
1217
|
export const namespaceKeys = [${namespaceKeys.map((key) => `"${key}"`).join(", ")}] as const;
|
|
1218
|
+
export const languages = [${languages.map((lang) => `"${lang}"`).join(", ")}] as const;
|
|
1201
1219
|
|
|
1202
1220
|
export type TranslationKey = typeof translationKeys[number];
|
|
1203
1221
|
export type TranslationNamespace = typeof namespaceKeys[number];
|
|
1222
|
+
export type Language = typeof languages[number];
|
|
1204
1223
|
`;
|
|
1205
1224
|
function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
1206
1225
|
console.log("=====");
|
|
@@ -1225,11 +1244,13 @@ function generateTranslationTypes(projectRoot = process.cwd()) {
|
|
|
1225
1244
|
const keys = Object.keys(translations[namespace] || {});
|
|
1226
1245
|
allKeys = allKeys.concat(keys);
|
|
1227
1246
|
}
|
|
1247
|
+
const pluralBaseKeys = extractPluralBaseKeys(allKeys);
|
|
1248
|
+
allKeys = allKeys.concat(pluralBaseKeys);
|
|
1228
1249
|
const outputDir = path3.dirname(outputFilePath);
|
|
1229
1250
|
if (!fs3.existsSync(outputDir)) {
|
|
1230
1251
|
fs3.mkdirSync(outputDir, { recursive: true });
|
|
1231
1252
|
}
|
|
1232
|
-
const typeString = typeTemplate(allKeys, namespaces);
|
|
1253
|
+
const typeString = typeTemplate(allKeys, namespaces, config.languages);
|
|
1233
1254
|
fs3.writeFileSync(outputFilePath, typeString, "utf8");
|
|
1234
1255
|
console.log(`Generated types with ${allKeys.length} keys and ${namespaces.length} namespaces`);
|
|
1235
1256
|
console.log(`Output: ${outputFilePath}`);
|
|
@@ -2214,6 +2235,7 @@ export {
|
|
|
2214
2235
|
createEmptyTranslationStructure,
|
|
2215
2236
|
detectExistingTranslations,
|
|
2216
2237
|
ensureTranslationsStructure,
|
|
2238
|
+
extractPluralBaseKeys,
|
|
2217
2239
|
extractVariables,
|
|
2218
2240
|
fillNamespace,
|
|
2219
2241
|
findUnusedKeys,
|