Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 29, 2025

This PR adds support for using the DeepL API as an alternative translation service in the ioBroker plugin, while maintaining full backward compatibility with the existing ioBroker translator service.

Problem

The ioBroker plugin currently uses the ioBroker translator service exclusively for translating changelog entries into multiple languages. Users requested the ability to use DeepL's API for potentially higher quality translations.

Solution

Added environment variable-based DeepL API integration with intelligent fallback:

Key Features

  • Environment Variable Configuration: Set DEEPL_API_KEY to enable DeepL translation
  • Dual API Support: Automatically detects and uses correct endpoint for DeepL Free (:fx suffix) vs Pro API keys
  • Multi-language Translation: Supports 9 languages (German, Spanish, French, Italian, Dutch, Polish, Portuguese, Russian, Chinese)
  • Robust Fallback: Automatically falls back to ioBroker translator if DeepL fails for any reason
  • Zero Breaking Changes: Existing behavior unchanged when environment variable is not set

Usage

# Enable DeepL translation
export DEEPL_API_KEY="your-api-key:fx"  # Free tier
export DEEPL_API_KEY="your-api-key"     # Pro tier

# Run release as normal
npm run release patch

Implementation Details

The enhancement modifies the translateText function in packages/plugin-iobroker/src/translate.ts to:

  1. Check for DEEPL_API_KEY environment variable
  2. If present, attempt translation using DeepL API with appropriate endpoint
  3. Fall back to ioBroker translator on any failure (invalid key, network issues, etc.)
  4. Maintain original response format for seamless integration

Error Handling

  • Fail-fast validation: Tests API key with first language to catch invalid keys early
  • Partial failure tolerance: Individual language translation failures don't break the entire process
  • Graceful degradation: Complete fallback to ioBroker translator ensures releases never fail due to translation issues

Testing

Added comprehensive test suite covering:

  • Default ioBroker translator behavior (unchanged)
  • DeepL API success scenarios (free and pro keys)
  • Individual language failure handling
  • Complete DeepL failure with fallback to ioBroker

All existing tests continue to pass, ensuring no regressions.

Files Changed

  • packages/plugin-iobroker/src/translate.ts - Core DeepL integration logic
  • packages/plugin-iobroker/src/translate.test.ts - Comprehensive test coverage
  • README.md - Documentation for setup and usage

Implementation Success

This enhancement provides ioBroker developers with access to DeepL's high-quality translation API while maintaining the reliability and backward compatibility of the existing system.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • translator.iobroker.in
    • Triggering command: `node -e
      const axios = require('axios');
      const qs = require('querystring');

async function testIoBrokerTranslator() {
try {
const data = qs.stringify({
text: 'Added new feature',
together: true,
});

const response = await axios({
  method: 'post',
  url: 'REDACTED',
  data,
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  },
});

console.log('ioBroker translator response:');
console.log(JSON.stringify(response.data, null, 2));

} catch (error) {
console.log('Error testing ioBroker translator:', error.message);
}
}

testIoBrokerTranslator();` (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Enhance Translation in ioBroker plugin to use Deepl Free API</issue_title>
<issue_description>Please adjust the translation logic in the ioBroker Plugin so that, when a Deepl API key ENV variable is provided, Deepl is used to translate instead of the current ioBroker translator service</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #177

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add DEEPL_API_KEY environment variable support
- Fallback to ioBroker translator if DeepL fails
- Support both free (:fx) and pro API keys
- Add comprehensive tests for all scenarios
- Update README with configuration instructions

Co-authored-by: AlCalzone <17641229+AlCalzone@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Enhance Translation in ioBroker plugin to use Deepl Free API Enhance ioBroker plugin translation with DeepL API support Sep 29, 2025
@Copilot Copilot AI requested a review from AlCalzone September 29, 2025 11:44
Copilot finished work on behalf of AlCalzone September 29, 2025 11:44
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.

Enhance Translation in ioBroker plugin to use Deepl Free API
2 participants