Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Instructions and four skills for coding agents, installed by
[Symfony AI Mate](https://symfony.com/doc/current/ai/components/mate.html)
(`vendor/bin/mate discover`): create a translatable resource, search and
sort by translated fields, write translations over HTTP, and use a DTO as
the API resource. The bundle does not require Mate

## [2.3.0] - 2026-11-18

### Changed
Expand Down
22 changes: 22 additions & 0 deletions INSTRUCTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## locastic/api-platform-translation-bundle

Entity translations for API Platform and Doctrine ORM: one translation row for
each locale, with the locale resolved from each request. This extension has no
Mate tools. Its skills hold the complete setup, payloads and checks, so load
the skill for your task:

| Task | Skill |
|---|---|
| Make an entity translatable, or add a translated field | `api-translation-resource` |
| Search or sort a collection by a translated field | `api-translation-filters` |
| Send, edit or replace translations through the API (POST, PATCH, PUT) | `api-translation-writes` |
| Use a DTO class as the API resource of a translatable entity | `api-translation-dto` |

Installed skill names start with `mate-`.

### Rules

- Virtual getters on the translatable delegate to getTranslation(), which resolves the current locale and falls back to the fallback locale; virtual setters delegate to getOrCreateTranslation(), which targets the exact locale and creates the translation when missing.
- Set auto_create_translations: false so reads never write to the database; the default (true) keeps the legacy behavior where getTranslation() attaches an empty translation for a missing locale, which cascade persist can insert on the next flush. The default flips to false in 3.0.
- Prefer PATCH (application/merge-patch+json) for editing translations: it updates only the submitted locales. PUT is a full replace and removes locales absent from the payload.
- With a DTO as the API resource (stateOptions: new Options(entityClass: ...)), reads need nothing extra, but the bundle does not match submitted translations to their existing rows: in your state processor, call getOrCreateTranslation($locale) on the managed entity for each submitted locale (or match by locale in an Object Mapper transformer). The 'translation.groups' filter and the 'translations' group do not apply to a DTO; expose the translations as a DTO property keyed by locale.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ child service of the abstract parent
`locastic_api_platform_translation.doctrine.orm.filter.translation_order`,
pass `$properties`, and tag it `api_platform.filter`.

Coding agents:
--------------
The bundle ships instructions and skills for coding agents through
[Symfony AI Mate](https://symfony.com/doc/current/ai/components/mate.html).
In a project that uses Mate, `vendor/bin/mate discover` adds the bundle's
rules to the agent instructions (`mate/AGENT_INSTRUCTIONS.md`) and installs
four skills:

- `mate-api-translation-resource`: create a translatable entity, or add a
translated field.
- `mate-api-translation-filters`: search and sort by translated fields.
- `mate-api-translation-writes`: send translations with POST, PATCH and PUT.
- `mate-api-translation-dto`: use a DTO class as the API resource.

The bundle does not require Mate. The same files are in the package:
`INSTRUCTIONS.md` and the `skills/` directory.

## Contribution

If you have an idea on how to improve this bundle, feel free to contribute. If you have problems or you found some bugs, please open an issue.
Expand Down
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"api-platform/core": "^3.4 || ^4.0 || ^5.0",
"symfony/http-client": "^6.4 || ^7.0 || ^8.0"
},
"suggest": {
"symfony/ai-mate": "Installs this bundle's agent instructions and skills for coding agents"
},
"prefer-stable": true,
"autoload": {
"psr-4": {
Expand All @@ -59,6 +62,10 @@
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
},
"ai-mate": {
"instructions": "INSTRUCTIONS.md",
"skills": ["skills"]
}
},
"config": {
Expand Down
9 changes: 6 additions & 3 deletions context7.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
"tests",
"config",
"bin",
"vendor"
"vendor",
"skills"
],
"excludeFiles": [
"CONTRIBUTING.md",
"SECURITY.md"
"SECURITY.md",
"INSTRUCTIONS.md"
],
"rules": [
"A translatable resource extends AbstractTranslatable, implements createTranslation(), and maps translations as OneToMany with indexBy: 'locale', cascade: ['persist'], orphanRemoval: true.",
Expand All @@ -28,8 +30,9 @@
"When editing via PUT, include each existing translation's 'id' so its row is updated in place instead of replaced.",
"Clients select the locale with the ?locale= query parameter or the Accept-Language header, and can request all translations at once with ?groups[]=translations (the bundle's 'translation.groups' filter).",
"Filter and order collections by translated fields with the bundle's TranslationSearchFilter and TranslationOrderFilter (e.g. #[ApiFilter(TranslationSearchFilter::class, properties: ['title' => 'ipartial'])]); declare the translation entity's fields by their bare name ('title', not 'translations.title'). They match only the locale resolved from the request, unlike a core SearchFilter on 'translations.title', which matches every locale.",
"With a DTO as the API resource (stateOptions: new Options(entityClass: ...)), reads need nothing extra, but the bundle does not match submitted translations to their existing rows: in your state processor, call getOrCreateTranslation($locale) on the managed entity for each submitted locale (or match by locale in an Object Mapper transformer). The 'translation.groups' filter and the 'translations' group do not apply to a DTO; expose the translations as a DTO property keyed by locale.",
"Restrict accepted locales with framework.enabled_locales or the bundle's api_platform_translation.enabled_locales option (which takes precedence); unlisted locales fall back to the default locale.",
"Version 2.x requires PHP >= 8.2, API Platform ^3.4 || ^4.0, and Doctrine ORM ^3.0; use PHP 8 attributes, not Doctrine annotations, in mappings."
"Version 2.x requires PHP >= 8.2, API Platform ^3.4 || ^4.0 || ^5.0, and Doctrine ORM ^3.0; use PHP 8 attributes, not Doctrine annotations, in mappings."
],
"previousVersions": [
"v2.0.1",
Expand Down
Loading
Loading