Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 12, 2025

Summary

This PR implements a translation word API feature for the VK Bot that handles multiple query patterns in both Russian and English.

Features Implemented

  • Pattern Recognition: Supports various translation query patterns:

    • "Как перевести X на английский?" → Translates X to English, responds in Russian
    • "Как переводится X?" → Translates X to Russian (inferred), responds in Russian
    • "How to translate X?" → Translates X to English (inferred), responds in English
    • "What is translation of X?" → Translates X to English (inferred), responds in English
    • "translate X" / "перевод X" → Generic translation commands
  • Smart Language Detection:

    • Detects message language and word language independently
    • Infers translation direction based on context
    • Responds in the same language as the query
  • Free Translation API: Uses MyMemory translation service (no API key required)

  • Proper Unicode Handling: URL-encodes words for correct API requests

  • Error Handling: Graceful fallback messages in appropriate language

Technical Details

Files Modified:

  • python/patterns.py: Added regex patterns for translation commands
  • python/modules/commands.py: Implemented translate_word() method with language detection logic
  • python/__main__.py: Registered new translation command patterns

Translation Logic:

  1. Extract word from matched pattern
  2. Detect message language (Russian/English) excluding the word itself
  3. Detect word language (Russian/English)
  4. Determine source→target language direction
  5. Call MyMemory API with URL-encoded word
  6. Format response in appropriate language

Test Coverage

Added comprehensive tests in examples/ directory:

  • Pattern matching validation
  • Language detection logic
  • API functionality testing
  • End-to-end workflow verification

Example Usage

User: "Как перевести hello на английский?"
Bot: "hello" переводится как "Алло"

User: "How to translate красота?" 
Bot: "красота" translates to "beauty"

User: "Как переводится beautiful?"
Bot: "beautiful" переводится как "красивый"

Fixes #130

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #130
@konard konard self-assigned this Sep 12, 2025
- Add translation patterns for Russian and English queries
- Implement translate_word() method with language detection
- Support queries like "Как перевести X на английский?" and "How to translate X?"
- Use MyMemory free translation API with proper URL encoding
- Respond in the same language as the query
- Add comprehensive tests for pattern matching and API functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] VK Bot: Translation of word API VK Bot: Translation of word API Sep 12, 2025
@konard konard marked this pull request as ready for review September 12, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VK Bot: Translation of word API

2 participants