i18next-mcp-server
Version:
A comprehensive Model Context Protocol (MCP) server for i18next translation management, health checking, and automated translation workflows
281 lines (280 loc) • 7.52 kB
TypeScript
import { z } from 'zod';
export declare const I18nConfigSchema: z.ZodObject<{
projectRoot: z.ZodString;
localesPath: z.ZodDefault<z.ZodString>;
languages: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
namespaces: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
defaultLanguage: z.ZodDefault<z.ZodString>;
defaultNamespace: z.ZodDefault<z.ZodString>;
keySeparator: z.ZodDefault<z.ZodString>;
nsSeparator: z.ZodDefault<z.ZodString>;
interpolation: z.ZodDefault<z.ZodObject<{
prefix: z.ZodDefault<z.ZodString>;
suffix: z.ZodDefault<z.ZodString>;
}, "strip", z.ZodTypeAny, {
prefix: string;
suffix: string;
}, {
prefix?: string | undefined;
suffix?: string | undefined;
}>>;
backup: z.ZodDefault<z.ZodObject<{
enabled: z.ZodDefault<z.ZodBoolean>;
path: z.ZodDefault<z.ZodString>;
}, "strip", z.ZodTypeAny, {
path: string;
enabled: boolean;
}, {
path?: string | undefined;
enabled?: boolean | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
projectRoot: string;
localesPath: string;
languages: string[];
namespaces: string[];
defaultLanguage: string;
defaultNamespace: string;
keySeparator: string;
nsSeparator: string;
interpolation: {
prefix: string;
suffix: string;
};
backup: {
path: string;
enabled: boolean;
};
}, {
projectRoot: string;
localesPath?: string | undefined;
languages?: string[] | undefined;
namespaces?: string[] | undefined;
defaultLanguage?: string | undefined;
defaultNamespace?: string | undefined;
keySeparator?: string | undefined;
nsSeparator?: string | undefined;
interpolation?: {
prefix?: string | undefined;
suffix?: string | undefined;
} | undefined;
backup?: {
path?: string | undefined;
enabled?: boolean | undefined;
} | undefined;
}>;
export type I18nConfig = z.infer<typeof I18nConfigSchema>;
export interface TranslationKey {
key: string;
namespace: string;
value: string;
interpolationParams: string[];
context?: string;
plural?: boolean;
}
export interface TranslationFile {
language: string;
namespace: string;
path: string;
content: Record<string, unknown>;
lastModified: Date;
size: number;
}
export interface HealthCheckResult {
summary: {
totalIssues: number;
errors: number;
warnings: number;
info: number;
score: number;
};
files: Record<string, {
keyCount: number;
issueCount: number;
issues: ValidationIssue[];
qualityScore: QualityScore;
}>;
issues: ValidationIssue[];
recommendations: string[];
timestamp: Date;
}
export interface ValidationIssue {
type: string;
severity: 'error' | 'warning' | 'info';
message: string;
file?: string;
suggestion?: string;
location?: {
language?: string;
namespace?: string;
key?: string;
};
details?: Record<string, unknown>;
}
export interface QualityScore {
score: number;
grade: 'A' | 'B' | 'C' | 'D' | 'F';
totalKeys: number;
errorCount: number;
warningCount: number;
}
export interface HealthIssue {
type: 'missing_key' | 'orphaned_key' | 'invalid_json' | 'inconsistent_interpolation' | 'untranslated_content' | 'malformed_placeholder' | 'empty_value' | 'suspicious_html';
severity: 'error' | 'warning' | 'info';
key?: string;
description: string;
suggestion?: string;
affectedLanguages?: string[];
}
export interface CoverageReport {
overall: {
totalKeys: number;
translatedKeys: number;
percentage: number;
};
byLanguage: Record<string, {
totalKeys: number;
translatedKeys: number;
percentage: number;
missingKeys: string[];
}>;
byNamespace: Record<string, {
totalKeys: number;
translatedKeys: number;
percentage: number;
}>;
recommendations: string[];
generatedAt: Date;
}
export interface UsageAnalysis {
totalKeysInFiles: number;
usedKeys: string[];
unusedKeys: string[];
missingKeys: string[];
namespaceUsage: Record<string, {
keysUsed: number;
totalKeys: number;
files: string[];
}>;
filesCovered: number;
totalFiles: number;
coveragePercentage: number;
generatedAt: Date;
}
export interface MigrationOperation {
type: 'add_key' | 'remove_key' | 'rename_key' | 'move_key' | 'update_value';
key: string;
newKey?: string;
value?: string;
namespace?: string;
newNamespace?: string;
affectedLanguages: string[];
description: string;
}
export interface MigrationScript {
operations: MigrationOperation[];
description: string;
createdAt: Date;
canRollback: boolean;
}
export interface QualityAnalysis {
consistency: {
score: number;
issues: Array<{
key: string;
issue: string;
languages: string[];
}>;
};
completeness: {
score: number;
missingTranslations: Record<string, string[]>;
};
interpolation: {
score: number;
mismatches: Array<{
key: string;
languages: Record<string, string[]>;
}>;
};
placeholders: {
score: number;
malformed: Array<{
key: string;
language: string;
issue: string;
}>;
};
overallScore: number;
generatedAt: Date;
}
export interface I18nTool {
name: string;
description: string;
inputSchema: z.ZodType<unknown>;
}
export interface ServerEvent {
type: 'file_changed' | 'file_added' | 'file_removed' | 'scan_completed' | 'health_check_completed';
timestamp: Date;
data: unknown;
}
export declare class I18nError extends Error {
code: string;
details?: unknown | undefined;
constructor(message: string, code: string, details?: unknown | undefined);
}
export declare class ValidationError extends I18nError {
constructor(message: string, details?: unknown);
}
export declare class FileSystemError extends I18nError {
constructor(message: string, details?: unknown);
}
export declare class ConfigurationError extends I18nError {
constructor(message: string, details?: unknown);
}
export interface KeyOperation {
type: 'add' | 'remove' | 'rename' | 'sync';
key: string;
languages?: string[];
namespaces?: string[];
}
export interface KeyAddition extends KeyOperation {
type: 'add';
value?: string;
defaultValue: string;
overwrite?: boolean;
}
export interface KeyRemoval extends KeyOperation {
type: 'remove';
}
export interface KeyRename extends KeyOperation {
type: 'rename';
oldKey: string;
newKey: string;
overwrite?: boolean;
}
export interface BatchKeyOperation {
operations: KeyOperation[];
createBackup?: boolean;
continueOnError?: boolean;
}
export interface KeyConflict {
key: string;
language: string;
namespace: string;
existingValue: unknown;
}
export interface OperationResult {
success: boolean;
operations: Array<{
type: string;
key: string;
newKey?: string;
language: string;
namespace: string;
value?: unknown;
timestamp: string;
}>;
conflicts: KeyConflict[];
errors: string[];
}