@lit/localize provides first-class localization for Lit templates. It supports both plain strings and lit-html TemplateResult values (including embedded expressions), letting translators preserve markup structure without touching JavaScript.The library ships in two modes:
Mode
How it works
Best for
Runtime
Loads translation bundles on demand; supports dynamic locale switching
Apps that need live locale changes without a full reload
Transform
A build step rewrites msg() calls with the translated strings; @localized decorators are removed
Minimal runtime overhead; one bundle per locale
The @lit/localize-tools package provides the lit-localize CLI used for both modes.
import {msg} from '@lit/localize';// Simple stringconst label = msg('Save changes');// With explicit id and descriptionconst label = msg('Save changes', { id: 'save-button-label', desc: 'Label for the save button in the toolbar',});
Untagged template literals with expressions (\Hello $`) cannot be used with msg()because the values cannot be captured at runtime. Use thestr` tag instead:
import {msg, str} from '@lit/localize';const greeting = msg(str`Hello ${this.userName}!`);
The str tag returns a StrResult that msg() can interpolate into the translation.
interface RuntimeConfiguration { /** Locale code of the source templates (also the initial active locale). */ sourceLocale: string; /** Locale codes this project supports (do not include sourceLocale). */ targetLocales: Iterable<string>; /** Returns a Promise for the locale module at the given locale code. */ loadLocale: (locale: string) => Promise<LocaleModule>;}
Transform mode produces the lowest possible runtime overhead. The lit-localize CLI rewrites your source files, replacing msg() calls with the translated literal and removing @localized() decorators.