PHPackages                             mgamadeus/ddd-common-translations - 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. mgamadeus/ddd-common-translations

ActiveLibrary[Localization &amp; i18n](/categories/localization)

mgamadeus/ddd-common-translations
=================================

Texts, entity translations, app translations, embeddings for mgamadeus/ddd

1.0.23(1mo ago)0167↓50%MITPHP

Since Apr 14Pushed 2mo agoCompare

[ Source](https://github.com/mgamadeus/ddd-translations)[ Packagist](https://packagist.org/packages/mgamadeus/ddd-common-translations)[ RSS](/packages/mgamadeus-ddd-common-translations/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (8)Versions (24)Used By (0)

mgamadeus/ddd-common-translations
=================================

[](#mgamadeusddd-common-translations)

Texts, entity translations, app UI translations, embeddings, and language detection for the [mgamadeus/ddd](https://github.com/mgamadeus/ddd) framework.

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

[](#installation)

```
composer require mgamadeus/ddd-common-translations
```

This pulls in [ddd-ai](https://github.com/mgamadeus/ddd-ai) and [ddd-common-political](https://github.com/mgamadeus/ddd-political) automatically.

What it does
------------

[](#what-it-does)

Unified translation system with two main capabilities:

### Entity translations (AITranslationsService)

[](#entity-translations-aitranslationsservice)

Translates any entity property marked with `#[Translatable]` to multiple locales via AI:

```
$aiTranslationsService = AITranslationsService::getService();
$aiTranslationsService->translateEntities($entitySet, $locales);
```

### App UI translations (AppTranslationsService)

[](#app-ui-translations-apptranslationsservice)

Manages application UI string translations with:

- **AppTranslationKey** — translation keys with templates, hints, context flags
- **AppTranslationValue** — per language/country/writing style values
- **AppTranslationDefaultTerm** — glossary for consistent terminology
- **Completeness tracking** — per-locale coverage metrics (formal + informal)
- **AI generation** — batch translate untranslated keys via LLM

```
$service = AppTranslationsService::getService();

// Generate translations for a locale
$result = $service->generateAppTranslationsForLocale($locale, writingStyle: 'FORMAL');

// Generate for all active locales
$results = $service->generateAppTranslationsForActiveLocales();
```

Service registration
--------------------

[](#service-registration)

Add to your project's `services.yaml`:

```
# DDD Module: ddd-common-translations
DDD\Domain\Common\Services\AppTranslations\:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-common-translations/src/Domain/Common/Services/AppTranslations/*'
    public: true

DDD\Domain\Common\Services\Translations\:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-common-translations/src/Domain/Common/Services/Translations/*'
    public: true
```

AppTranslatableService (DB-backed translations, optional)
---------------------------------------------------------

[](#apptranslatableservice-db-backed-translations-optional)

By default, the DDD core's `TranslatableService::translateKey()` reads from `config/app/Common/Translations.php` (hardcoded translations array). The module ships `AppTranslatableService` which overrides `translateKey()` to read from `AppTranslationKey` + `AppTranslationValue` entities in the database — letting you manage translations via admin UI instead of code.

To activate, override the core service in your `services.yaml`:

```
# Use DB-backed translations instead of config array
DDD\Domain\Base\Services\TranslatableService:
    class: DDD\Domain\Common\Services\Translations\AppTranslatableService
    public: true
```

The fallback chain is identical to the core (language+country+style → no country → alt writing style → default language → first available → key itself), just sourced from the DB with APC caching at each step (1-hour TTL).

### Text processing

[](#text-processing)

- **Text / Texts** — base text entities with locale, writing style, context
- **Translation** — subclass of Text representing a translated version
- **TextEmbedding** — vector representation via OpenAI embeddings API
- **DetectedLanguage** — AI-powered language detection

Prompt configuration
--------------------

[](#prompt-configuration)

The module ships generic prompt templates in `config/app/AI/Prompts/Common/`:

PromptPurpose`Translations/AppTranslations/SingleLocaleFormal.md`App UI translations (formal tone)`Translations/AppTranslations/SingleLocaleInformal.md`App UI translations (informal tone)`Translations/Entity/Translatable.md`Entity property translations`Texts/DetectedLanguage.md`Language detection### Overriding prompts

[](#overriding-prompts)

Place a file at the same path in your project's `config/app/AI/Prompts/` to override. Use this to add domain-specific context, tone, or terminology rules.

### Prompt constants

[](#prompt-constants)

Use `TranslationPrompts` to reference prompt names:

```
use DDD\Domain\Common\Entities\Texts\TranslationPrompts;

TranslationPrompts::APP_TRANSLATIONS_SINGLE_LOCALE_FORMAL
TranslationPrompts::APP_TRANSLATIONS_SINGLE_LOCALE_INFORMAL
TranslationPrompts::ENTITY_TRANSLATABLE
TranslationPrompts::DETECTED_LANGUAGE
```

Async translation processing
----------------------------

[](#async-translation-processing)

The module includes message handlers for asynchronous translation via Symfony Messenger.

### Messenger configuration

[](#messenger-configuration)

Add the `app_translations` transport to your `config/symfony/default/packages/messenger.yaml`:

```
framework:
    messenger:
        transports:
            app_translations: '%env(MESSENGER_TRANSPORT_DSN_RABBITMQ)%/app_translations'
            # Or for synchronous processing:
            # app_translations: 'sync://'
        routing:
            'DDD\Domain\Common\MessageHandlers\AppTranslationsMessage': app_translations
```

### Message handler service binding

[](#message-handler-service-binding)

Register the message handler in your `services.yaml` with the messenger logger:

```
DDD\Domain\Common\MessageHandlers\:
    resource: '%kernel.project_dir%/vendor/mgamadeus/ddd-common-translations/src/Domain/Common/MessageHandlers/*Handler.php'
    tags: ['messenger.message_handler']
    bind:
        Psr\Log\LoggerInterface $messengerLogger: '@monolog.logger.messenger'
```

### Environment variables

[](#environment-variables)

```
# RabbitMQ transport DSN for async message processing
MESSENGER_TRANSPORT_DSN_RABBITMQ=amqp://guest:guest@localhost:5672/%2f
```

Hardcoded fallback translations
-------------------------------

[](#hardcoded-fallback-translations)

The DDD core's `TranslatableService` reads `config/app/Common/Translations.php` as a last-resort fallback for system messages. This file is **project-specific** — each project maintains its own with domain-relevant strings:

```
// config/app/Common/Translations.php
return [
    'Welcome' => [
        'de::FORMAL' => 'Willkommen',
        'en::FORMAL' => 'Welcome',
        'fr::FORMAL' => 'Bienvenue',
    ],
];
```

The module does not ship this file — create it in your project as needed.

Argus endpoints
---------------

[](#argus-endpoints)

Argus repoEndpointCachePurpose`ArgusTranslation``POST:/rc-translations/deepl/translate`1 dayDeepL translation`ArgusTranslations``POST:/ai/openRouter/chatCompletions`noneLLM batch translation`ArgusTextEmbedding``POST:/ai/openRouter/embeddings`1 dayText vectorization`ArgusDetectedLanguage``POST:/ai/openRouter/chatCompletions`noneLanguage detectionAll require `ARGUS_API_ENDPOINT` to be configured (see [ddd-argus](https://github.com/mgamadeus/ddd-argus)).

Database tables
---------------

[](#database-tables)

The AppTranslations system creates three tables:

- `AppTranslationKeys` — translation keys with metadata
- `AppTranslationValues` — per-key translations (unique on key + language + virtual country)
- `AppTranslationDefaultTerms` — glossary/terminology mappings

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance88

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Recently: every ~11 days

Total

23

Last Release

38d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2896811?v=4)[mgamadeus](/maintainers/mgamadeus)[@mgamadeus](https://github.com/mgamadeus)

---

Top Contributors

[![mgamadeus](https://avatars.githubusercontent.com/u/2896811?v=4)](https://github.com/mgamadeus "mgamadeus (23 commits)")

### Embed Badge

![Health badge](/badges/mgamadeus-ddd-common-translations/health.svg)

```
[![Health](https://phpackages.com/badges/mgamadeus-ddd-common-translations/health.svg)](https://phpackages.com/packages/mgamadeus-ddd-common-translations)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
