Skip to content

feat(translate): Add automatic message translation to player language#335

Open
SolverNA wants to merge 2 commits intoFlectone:masterfrom
SolverNA:master
Open

feat(translate): Add automatic message translation to player language#335
SolverNA wants to merge 2 commits intoFlectone:masterfrom
SolverNA:master

Conversation

@SolverNA
Copy link
Copy Markdown

Summary

This PR implements automatic message translation based on player's client language settings. Messages are now automatically translated to each player's locale, with an option to toggle between original and
translation.

Changes

  • TranslatedMessage model: Stores original text and all translations by locale
  • Auto-translation system: Translates messages once per unique locale (not per player)
  • Toggle command: /toggleoriginal to switch between original and translated message
  • Optimized API usage: 100 players with 4 languages = 4 API requests (not 100!)
  • Updated localizations: Button now toggles original/translation instead of creating new message

How it works

  1. Player sends message in their language (e.g., "Hello" in en_us)
  2. System detects all unique locales on server (e.g., ru_ru, de_de, fr_fr)
  3. Translates message once per locale (3 API requests total)
  4. Each player receives message in their language
  5. Click button on message to see original text

Configuration

Requires language.by-player: true in config.yml and translation API setup (Google/Yandex/DeepL).

Testing

Tested with multiple players using different client languages. Translation and toggle functionality working as expected.

Note

Paper/Bukkit module has pre-existing compilation errors (missing Paper-specific classes). Core module compiles successfully. Fabric, BungeeCord, and Velocity versions work perfectly.

  - Created TranslatedMessage model to store all message translations
  - Extended HistoryMessage to support original/translation toggle
  - Added /toggleoriginal command to switch between original and translation
  - Implemented automatic translation to all unique server locales (API request optimization)
  - Updated localizations: button now toggles original/translation instead of creating new message
  - Added PulseAutoTranslateListener to handle auto-translation in MessagePrepareEvent
  - Modified DeleteModule to work with translations and toggling

  Now each message is automatically translated to the receiver's language.
  Button on message allows switching between original and translation.
@TheFaser
Copy link
Copy Markdown
Member

Разве такой автоматический перевод не добавляет задержку в чат у сообщений?

@SolverNA
Copy link
Copy Markdown
Author

Да сег сделаю асинхронный перевод

  - Created TranslationCacheService with MyMemory API integration
  - Added TRANSLATION_CACHE (24h, 50000 entries) for persistent translation storage
  - Integrated MyMemory API as fallback before main translation service
  - Converted translateToAllLocales to async with CompletableFuture for parallel translations
  - Added useMyMemory config option (default: true)
  - Added MYMEMORY service type to translation services
  - Updated configs for minecraft and hytale platforms

  Benefits:
  - No chat delay: original message sent immediately, translations load in background
  - MyMemory provides free cached translations (10k requests/day)
  - Parallel translation requests instead of sequential
  - Local cache reduces API calls for repeated phrases
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.

2 participants