# Development Standards

## Code Language Requirements

### 1. Comments
- **All code comments must be in English**
- Includes the following (not limited to):
  - Function/method comments
  - Inline comments
  - Code block explanations
  - TODO/FIXME comments

### 2. Logging
- **All log output must be in English**
- Includes the following (not limited to):
  - `logger.log()` info logs
  - `logger.warn()` warning logs
  - `logger.error()` error logs
  - `console.log()` debug output

### 3. Error Messages
- **Error messages must support internationalization (i18n)**
- **User-facing error messages**: Display in the user's selected language (Japanese/Chinese/English) via i18n system
- **Debug/development error messages**: Display in the user's selected language via i18n system
- **Exception messages**: Use i18n for internationalized error messages

## Examples

### Correct Comments and Logs (English + i18n)

```typescript
// Get embeddings for texts
async getEmbeddings(texts: string[]): Promise<number[][]> {
  this.logger.log(`Getting embeddings for ${texts.length} texts`);
  
  try {
    // Call API to get embeddings
    const response = await this.callEmbeddingAPI(texts);
    return response.data;
  } catch (error) {
    this.logger.error('Failed to get embeddings', error);
    // Use i18n for user-facing error messages
    throw new Error(this.i18n.t('errors.embeddingGenerationFailed'));
  }
}
```

### Using i18n for Error Messages

```typescript
import { I18nService } from './i18n.service';

async processDocument(file: Express.Multer.File) {
  try {
    // Process document...
    return result;
  } catch (error) {
    // Error message in user's selected language
    throw new Error(this.i18n.t('errors.documentProcessingFailed', {
      filename: file.originalname
    }));
  }
}
```

## Compliance Standards

1. **During code reviews, always check the language of comments and logs**
2. **New code must follow English comments and logs standards**
3. **When refactoring existing code, update comments and logs to English simultaneously**
4. **All error messages must use the i18n system for internationalization**

## Validation i18n Rules

### class-validator Limitation
The `@MinLength`, `@MaxLength`, `@IsEmail`, etc. decorators from `class-validator` have a **static `message` property** that cannot access NestJS's `I18nService` at runtime. Therefore:

- **DO NOT** use hardcoded messages in validation decorators like:
  ```typescript
  @MinLength(8, { message: 'Password must be at least 8 characters long' })
  ```

- **DO** perform validation in the controller layer with i18n support:
  ```typescript
  if (password.length < 6) {
    throw new BadRequestException(this.i18nService.getErrorMessage('passwordMinLength'));
  }
  ```

- **OR** remove the decorator and rely on controller-level validation only

### Adding New Validation Rules
When adding new validation to DTOs, ensure validation messages are internationalized by:
1. Adding the i18n key to `server/src/i18n/messages.ts`
2. Adding validation logic in the controller or service layer using `I18nService`

