UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

125 lines (124 loc) 4.29 kB
import { TranslationFile } from "../../../types/translation.types"; import { TranslationFileContext } from "../types/translation.additional"; /** * Finds and analyzes react-i18next translation files in a project */ export declare class ReactI18nextFileFinder { private context; private translationFiles; private mainTranslationFile; private namespaceFiles; /** * Creates a new react-i18next translation file finder * @param context Translation file context */ constructor(context: TranslationFileContext); /** * Finds all react-i18next translation files in the project * @returns Promise resolving when files are found */ findAllTranslationFiles(): Promise<void>; /** * Gets the discovered translation files * @returns Array of translation files */ getTranslationFiles(): TranslationFile[]; /** * Gets the main translation file (largest one or main namespace) * @returns Main translation file or null if none found */ getMainTranslationFile(): TranslationFile | null; /** * Gets translation files organized by namespace * @returns Map of namespace to translation files */ getNamespaceFiles(): Map<string, TranslationFile[]>; /** * Gets files for a specific namespace * @param namespace Namespace to get files for * @returns Array of translation files for the namespace */ getFilesForNamespace(namespace: string): TranslationFile[]; /** * Finds react-i18next translation files in common locations */ private findReactI18nextFiles; /** * Finds translation files in a directory (react-i18next structure) * @param dirPath Directory path * @returns Promise that resolves to an array of translation files */ private findFilesInDirectory; /** * Finds translation files within a language directory * @param languagePath Path to the language directory * @param languageCode Language code (e.g., 'en', 'fr') * @returns Promise that resolves to an array of translation files */ private findLanguageFiles; /** * Determines if a directory name represents a language code * @param dirName Directory name * @returns Boolean indicating if it's a language directory */ private isLanguageDirectory; /** * Organizes translation files by namespace */ private organizeFilesByNamespace; /** * Extracts namespace from file path * @param file Translation file * @returns Namespace string */ private extractNamespaceFromFile; /** * Counts the number of translation entries in a file (recursive) * @param obj Translation object * @param prefix Optional prefix for recursive calls * @returns Number of translations */ private countTranslationEntries; /** * Determines the main translation file * @returns The main translation file or null if none found */ private determineMainTranslationFile; /** * Analyzes the translation file structure for react-i18next * @param file Translation file to analyze * @returns Analysis information about the file */ analyzeReactI18nextFile(file: TranslationFile): { keysCount: number; nestedLevels: number; languageCode: string | null; namespace: string; format: "flat" | "nested"; hasPlurals: boolean; hasInterpolation: boolean; }; /** * Checks if the translation file contains pluralization keys * @param content Translation content * @returns Boolean indicating if plurals are present */ private checkForPlurals; /** * Checks if the translation file contains interpolation * @param content Translation content * @returns Boolean indicating if interpolation is present */ private checkForInterpolation; /** * Gets information about the react-i18next setup * @returns Information about react-i18next configuration */ detectReactI18nextSetup(): { structure: "namespace-based" | "language-based" | "mixed"; languages: string[]; namespaces: string[]; hasPlurals: boolean; hasInterpolation: boolean; }; }