Search by

survos / lingua-bundle

tacman1123

interact with Survos Lingua Server (aka translation server). Does not translate directly

Package info

github.com/survos/lingua-bundle

Type:symfony-bundle

pkg:composer/survos/lingua-bundle

Fund package maintenance!

kbond

Statistics

Installs: 1 141

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 2

2.45.94 2026-11-27 11:37 UTC

This package is auto-updated.

Last update: 2026-11-27 11:37:57 UTC


README

Synchronize application translation requests and results with the Lingua server. Babel supplies local translated values to application entities.

Features

  • Twig extension with custom filters and functions
  • Main service class for business logic
  • Controller with example routes
  • Console command for CLI operations
  • Configurable via environment variables

Installation

Install the bundle using Composer:

composer require survos/lingua-bundle

If you're using Symfony Flex, the bundle will be automatically registered. Otherwise, add it to your config/bundles.php:

return [
    // ...
    Survos\LinguaBundle\SurvosLinguaBundle::class => ['all' => true],
];

Configuration

Configure the bundle in config/packages/lingua.yaml:

survos_lingua:
  api_key: '%env(LINGUA_API_KEY)%'

Or set environment variables:

LINGUA_API_KEY=your_value_here

Usage

This bundle provides various components depending on your configuration. Check the generated service classes and controllers for specific usage examples.

Being told when a string is translated

Translation on the lingua server is asynchronous, and the historical way to collect results was to poll with lingua:pull — a job that usually finds nothing, and that nobody schedules until a locale turns up empty in production.

Set a callback URL and lingua announces them instead:

LINGUA_CALLBACK_URL=https://your-app.example/webhook/lingua
LINGUA_WEBHOOK_SECRET=<same value the lingua server signs with>

lingua:push then sends each string's Str.code as a ref, the server records a subscription per (string × target locale), and POSTs a signed translation.completed carrying up to 500 finished translations inline. TranslationUpdateApplier writes them to StrTranslation and dispatches TranslationUpdatedEvent for app-specific work (reindexing, cache busting).

In the app:

# config/routes/webhook.yaml
webhook:
    resource: '@FrameworkBundle/Resources/config/routing/webhook.php'
    prefix: /webhook

# config/packages/webhook.yaml
framework:
    webhook:
        routing:
            lingua:
                service: Survos\LinguaBundle\Webhook\LinguaWebhookRequestParser
                secret: '%env(default::LINGUA_WEBHOOK_SECRET)%'

# config/packages/messenger.yaml — REQUIRED, or the endpoint's 202 is a lie
framework:
    messenger:
        routing:
            'Symfony\Component\RemoteEvent\Messenger\ConsumeRemoteEventMessage': lingua_callback

Leave LINGUA_CALLBACK_URL unset and nothing changes — no subscriptions are created and lingua:pull remains the way to collect results.

Full contract: kit-bundle/docs/webhooks.md.

Replaced LinguaWebhookController, which checked an X-Api-Key by hand and whose route was never registered. See survos-sites/mediary#8.

Testing

Run the test suite:

./vendor/bin/phpunit

License

This bundle is released under the MIT license. See the LICENSE file for details.

Shared admin navigation

When menu-bundle is installed, Lingua contributes its available Overview and Translation sandbox routes to ADMIN_NAVBAR_MENU. Tabler and EZ render the same menu event; no application-specific listener is required. CLI/API-only consumers do not need menu-bundle. Menu visibility is controlled by the layout; it does not replace route authorization.

Optional local DuckDB storage (integration in progress)

The default remains application-database storage. The DuckDB implementation currently covers Lingua harvesting, push, pull, completion checks, and inbound callbacks. Babel entity registration, property hydration, catalogue loading, and translated search still use the application database. Do not enable this in an application yet: the Babel integration must be completed first so both sides select the same store.

The configuration being exercised by the storage/synchronization tests is:

survos_lingua:
    storage: '%env(LINGUA_STORAGE)%'
    duckdb_path: '%env(LINGUA_DUCKDB_PATH)%'
# .env — production stays on its existing app database
LINGUA_STORAGE=app
LINGUA_DUCKDB_PATH=

# .env.local — once the Babel integration is available
LINGUA_STORAGE=duckdb
LINGUA_DUCKDB_PATH=/absolute/persistent/dummy-lingua.duckdb

DuckDB requires PDO DuckDB and survos/duckdb-bundle with ConnectionCoordinator. Neither is loaded by the app backend. Unknown backend names fail rather than silently falling back. The file's parent directory must already exist and be writable; keep it outside disposable cache/build directories and on a local filesystem. Native WAL and coordinated short transactions protect writers. Network calls happen after releasing the file lock. Every process accessing the file must use the same coordinator.

The file contains two tables: str and str_tr, linked by str_code. Each source/target locale pair has one canonical translation; engine records provenance. Blank results never replace supplied text. Changing a stable catalogue key's source invalidates its old translations. Callback replays are idempotent and unknown local requests are skipped.

Maintenance commands:

  • lingua:storage:status: selected backend and DuckDB coverage.
  • lingua:storage:ensure es,fr: create missing DuckDB target requests.
  • lingua:storage:import-app: seed an empty file from standard app str/str_tr tables without modifying them. Existing engine variants are projected using Babel's newest nonblank row preference; this is a canonical cache import, not an archival export of every provider row. Custom entity/table mappings are not supported by this pilot importer. It materializes the data in memory and is intended for small pilots.

Switching configuration never transfers data. The app and DuckDB stores are independent. TermSets remain application data. There is no migration, release, or production runtime change implied by installing the default app backend.