Angular live editing
Live editing on Angular marks the text your app renders and opens Dialecto’s editor beside it. It works with
ngx-translate and with Transloco, and runs under ng serve only.
Install
npm install --save-dev @dialecto/angular
The component templates it reads need Angular 17 or later. The add-on needs the Vite dev server, so serve
must use "builder": "@angular/build:dev-server" in angular.json, and Angular 18 also needs @angular/build
installed. The webpack dev server (@angular-devkit/build-angular:dev-server) ignores the proxy entry’s
configure hook, so every request would be refused, and doctor fails on it.
Setup
Three edits, then one line in your app config.
-
Export the provider from
src/dialecto/dialecto.providers.ts. Use/ngx-translateor/transloco, whichever library your app uses.export { provideDialectoInContext } from '@dialecto/angular/ngx-translate'; -
Add a production stand-in,
src/dialecto/dialecto.providers.prod.ts. AnisDevMode()guard is not enough, because the add-on stays in the bundle. The file replacement is what keeps it out.export const provideDialectoInContext = (_options?: unknown): [] => [];In
angular.json, underbuild>configurations>production:"fileReplacements": [ { "replace": "src/dialecto/dialecto.providers.ts", "with": "src/dialecto/dialecto.providers.prod.ts" } ] -
Add
dialecto.proxy.mjsto the project root, and name it inserve>options>proxyConfig.ng servehas no plugin hook, so the dev server loads this file in its own process and the handler starts there. Theawaitis required on Angular 22.import { dialectoProxy } from '@dialecto/angular/dev'; export default await dialectoProxy();
Then add provideDialectoInContext() to appConfig.providers, imported from ./dialecto/dialecto.providers.
Set DIALECTO_URL, DIALECTO_PROJECT and DIALECTO_SCAN_TOKEN, and restart ng serve.
npx @dialecto/angular doctor checks all of this.
DIALECTO_IN_CONTEXT=off or provideDialectoInContext({ enabled: false }) turns the add-on off.
Editable text
- Both libraries. Drafts show live in ngx-translate and in Transloco.
- ICU messages. A draft of an ICU message, such as a plural, shows after a page reload, which the editor offers. The wrapped loaders fetch the drafts again, so they survive the reload.
- Transloco scopes. With Transloco as the only library, or
DIALECTO_ANGULAR_LIBRARY=transloco, every direct subfolder of the catalog folder that holds<locale>.jsonis a scope catalog, with the subfolder as its domain. ADIALECTO_CATALOGSlist replaces that search.
The catalog folder is the first of public/i18n, src/assets/i18n, public/assets/i18n, src/assets/locale
and public/locale, else DIALECTO_CATALOGS. The source locale is DIALECTO_SOURCE_LOCALE, default en.
Not marked:
- Catalogs that arrive through the bundle, such as
import en from './en.json'or inline scope loaders.doctorlists them. - Text that a wrapper function of your own builds, unless the scan’s
namesorfactorieslist it.
Pull requests
Your edits are saved in Dialecto as drafts on your project, and the pull request is opened from the sidebar. With DIALECTO_SAVE_TO_FILES=on, Save to files
writes them into your catalogs and scans the working tree afterwards, with the same DIALECTO_PROJECT,
DIALECTO_SCAN_TOKEN and DIALECTO_URL as npx @dialecto/angular scan. Without those, the files are still
written, and the sidebar says the rescan did not run.
Safety
The dev server accepts only requests from its own page: a secret header set by the proxy, a loopback peer and an
exact Origin. doctor prints the origin it accepts.