Socket
Book a DemoInstallSign in
Socket

@fw-components/localize

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fw-components/localize

Localizer built on top of lit-localize

latest
npmnpm
Version
2.3.2
Version published
Maintainers
2
Created
Source

@fw-components/localize

A localization utility built on top of lit-localize, providing simplified message extraction and runtime locale switching for web applications.

1. How it works

The package provides two main components:

  • CLI Tool: A command-line utility (fw-localize) that extracts localizable messages from your source code and generates translation files.

  • Runtime Library: Functions for loading translations and switching between locales in your application.

The localization workflow consists of:

  • Marking strings for translation in your code using msg()
  • Extracting these messages using the CLI tool
  • Translating the extracted messages
  • Loading and applying translations at runtime
// Example locales/es.json
{
  "Hello": "Hola",
}

2. Usage

CLI Usage

Extract messages from your source files:

npx fw-localize extract

Configuration is specified in a localize.json file:

{
  "sourceLocale": "en",
  "targetLocales": ["es", "fr", "de"],
  "tsConfig": "./tsconfig.json",
  "output": {
    "mode": "runtime",
    "outputDir": "./locales"
  },
  "interchange": {
    "format": "json"
  }
}

Runtime Usage

import { configureLocalization, msg } from '@fw-components/localize';

// Configure localization
const { getLocale, setLocale } = configureLocalization({
  sourceLocale: 'en',
  targetLocales: ['es', 'fr', 'de'],
  loadLocale: (locale) => import(`./locales/${locale}.js`)
});

// Use in your components
function renderGreeting(name) {
  return html`
    <h1>${msg("Hello")}</h1>
  `;
}

// Switch locale
await setLocale('es');

Note:

Use the msg() function to mark text for translation:

// For static strings
msg("Hello world")

// For strings with expressions
msg(`Hello ${username}`)

For more advanced usage and options, refer to the lit-localize documentation.

FAQs

Package last updated on 01 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.