/symfony-ux-skills:ux-translatorfrom symfony-ux-skills
Brings Symfony translations into JavaScript with trans(), ICU and plural support, type-checked keys in TypeScript. Use for client-side validation, toasts, dialogs, and chart labels.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Use your Symfony translations in JavaScript with a trans() function that behaves like the PHP translator: domains, locales, fallbacks, pluralization and the ICU Message Format. Translations are dumped to var/translations/ on cache warmup; with TypeScript, keys, parameters, domains and locales are type-checked.
Prefer rendering text in Twig when the server already knows it. Reach for UX Translator when JavaScript builds messages itself: client-side validation, toasts, confirmation dialogs, chart labels.
composer require symfony/ux-translator
Requires StimulusBundle. Flex creates the translator module:
// assets/translator.js (rename to translator.ts for type-checking)
import { createTranslator } from '@symfony/ux-translator';
import { messages, localeFallbacks, defaultLocale } from '../var/translations/index.js';
const translator = createTranslator({
messages,
localeFallbacks,
defaultLocale,
});
export const { trans } = translator;
| Asset pipeline | Extra step |
|---|---|
| AssetMapper | None: Flex adds @symfony/ux-translator to importmap.php, and the bundle maps the dump directory |
| Webpack Encore | npm install --force, then restart npm run watch |
import { trans } from './translator';
trans('cart.empty'); // domain "messages", current locale
trans('cart.items', { '%count%': 3 }); // pluralization
trans('cart.greeting', { '%name%': 'Fabien' }); // placeholder
trans('cart.title', {}, 'shop'); // another domain
trans('cart.title', {}, 'messages', 'fr'); // another locale
Parameters follow the PHP translator:
%name% needs { '%name%': 'Fabien' }. Pluralization reads %count% ({0} No item|{1} One item|]1,Inf] %count% items).messages+intl-icu.fr.yaml) take plain names: { count: 3, name: 'Fabien' }. Keys wrapped in % or {} are accepted too. The domain stays messages: the ICU version wins when both exist.A missing key returns the key itself.
Every domain and key is dumped by default, and all of it ends up in the JavaScript bundle. Narrow it:
# config/packages/ux_translator.yaml
ux_translator:
domains: [messages, validators] # or '!admin', or ['!admin', '!security']
keys_patterns: ['app.*', '!app.internal.*']
* matches any characters; a leading ! excludes. Avoid exposing admin or internal wording: anyone loading your JavaScript can read it.
The locale is the first one found in:
locale option of createTranslator();<html data-symfony-ux-translator-locale="{{ app.request.locale }}"> (Symfony format, de_AT);<html lang="{{ app.request.locale|replace({'_': '-'}) }}"> (W3C format, de-AT);defaultLocale option, since Symfony UX 3.7+ (the dump exports framework.default_locale);en.Change it at runtime with setLocale(); read it with getLocale():
export const { trans, setLocale, getLocale } = translator;
setLocale('de_AT');
Fallbacks follow localeFallbacks from the dump, as in PHP (de_AT falls back to de).
const translator = createTranslator({
messages,
localeFallbacks,
defaultLocale,
throwWhenNotFound: true,
});
export const { trans, setThrowWhenNotFound } = translator;
Enable it in development or tests to catch keys missing from the dump.
Translations are dumped on cache warmup. Since Symfony UX 3.1+, refresh only the JavaScript translations with:
php bin/console ux:translator:warm-cache
# config/packages/ux_translator.yaml (defaults)
ux_translator:
dump_directory: '%kernel.project_dir%/var/translations' # update assets/translator.js if changed
dump_typescript: true
domains: ~ # all domains
keys_patterns: [] # all keys
AssetMapper never reads the TypeScript types, so skip them in production there:
when@prod:
ux_translator:
dump_typescript: false
Keep them with Encore or Reprise and TypeScript: the build type-checks against them.
'%name%'), plain name only works for ICU messages.%count% as a number for classic messages, count for ICU.ux:translator:warm-cache and check domains / keys_patterns.var/translations/ on CI or in a Docker build stage: run cache:warmup before the asset build, and copy the directory into the Node stage.data-symfony-ux-translator-locale or lang on <html> from app.request.locale.domains and keys_patterns.symfony/ux-translator on Packagist.trans() in a controller for client-side messages.var/routes/, path() in JavaScript).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package./turboSymfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast]./twig-componentSymfony UX TwigComponent: reusable Twig buttons, cards, alerts and design system components. Use for twig: tags, #[AsTwigComponent], props, blocks, attributes.defaults(), anonymous components, computed properties, provide()/inject() and html_cva./ux-autocompleteSymfony UX Autocomplete: searchable selects and Ajax suggestions for large Symfony form lists. Use for EntityType, ChoiceType, Tom Select, the autocomplete option, #[AsEntityAutocompleteField], #[AsAutocompleteField], AutocompleterInterface, extra_options and tom_select_options.Other plugins' skills for the same job