PHPackages                             survos/translator-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. survos/translator-bundle

ActiveSymfony-bundle[Localization &amp; i18n](/categories/localization)

survos/translator-bundle
========================

Engine-agnostic translation client bundle (Symfony 7.3 / PHP 8.4) with LibreTranslate adapter and optional caching.

2.0.194(2mo ago)01221MITPHPPHP ^8.4

Since Sep 9Pushed 1mo agoCompare

[ Source](https://github.com/survos/translator-bundle)[ Packagist](https://packagist.org/packages/survos/translator-bundle)[ GitHub Sponsors](https://github.com/kbond)[ RSS](/packages/survos-translator-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (22)Versions (184)Used By (1)

Survos Translator Bundle
========================

[](#survos-translator-bundle)

A Symfony 7.3 / PHP 8.4 bundle that unifies multiple translation engines (DeepL, LibreTranslate, …), adds smart caching, and optional async processing via Messenger. Designed to replace the legacy `libre-bundle` in the Survos translation server.

> Target repo to integrate with next:

---

Features
--------

[](#features)

- ✅ Drop‑in service: `Survos\TranslatorBundle\Service\Translator`
- 🔌 Pluggable engines: DeepL, LibreTranslate (more welcome)
- 🧠 Cache‑first: Symfony Cache (PSR‑6/16) with per‑engine TTL &amp; busting
- 🚀 Async mode: Messenger message + worker for heavy workloads
- 📝 Rich metadata: hash, engine, source/target, confidence, token counts
- 🧪 Handy CLI for quick checks &amp; warmups

---

Installation
------------

[](#installation)

```
composer require survos/translator-bundle
```

If you use Symfony Flex, the bundle is auto‑enabled. Otherwise, add to `config/bundles.php`:

```
return [
    // ...
    Survos\TranslatorBundle\SurvosTranslatorBundle::class => ['all' => true],
];
```

---

Environment &amp; API Keys
--------------------------

[](#environment--api-keys)

Set the following in your `.env.local` (or server secrets). Only configure the engines you’ll use.

```
### Core ###
TRANSLATOR_DEFAULT_ENGINE=libre   # libre | deepl
TRANSLATOR_CACHE_TTL=86400        # seconds (1 day default)
TRANSLATOR_TIMEOUT=10             # HTTP seconds

### DeepL ###
DEEPL_API_KEY=\!\!put-your-key-here\!\!
# Optional: free vs pro endpoint auto‑detected by key suffix (-free). Override if needed:
DEEPL_BASE_URI=https://api-free.deepl.com/v2

### LibreTranslate ###
LIBRETRANSLATE_BASE_URI=https://translate.argosopentech.com
# If your instance requires a key:
LIBRETRANSLATE_API_KEY=
```

> Pro tip: keep **engine‑specific** keys/names distinct per environment to avoid accidental cross‑use.

---

Bundle Configuration
--------------------

[](#bundle-configuration)

Create `config/packages/survos_translator.yaml`:

```
survos_translator:
  default_engine: '%env(string:TRANSLATOR_DEFAULT_ENGINE)%'
  timeout: '%env(int:TRANSLATOR_TIMEOUT)%'
  cache_ttl: '%env(int:TRANSLATOR_CACHE_TTL)%'

  engines:
    deepl:
      api_key: '%env(DEEPL_API_KEY)%'
      base_uri: '%env(default:~:DEEPL_BASE_URI)%'  # null => autodetect
    libre:
      base_uri: '%env(LIBRETRANSLATE_BASE_URI)%'
      api_key: '%env(default::LIBRETRANSLATE_API_KEY)%'  # may be empty
```

### Optional: Dedicated Cache Pool

[](#optional-dedicated-cache-pool)

```
framework:
  cache:
    pools:
      survos_translator.cache:
        adapter: cache.app
        default_lifetime: 86400
```

The bundle will auto‑wire a pool named `survos_translator.cache` if present, otherwise falls back to `cache.app`.

---

Quick Start (Sync)
------------------

[](#quick-start-sync)

```
