Socket
Socket
Sign inDemoInstall

@vscode/l10n

Package Overview
Dependencies
Maintainers
7
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vscode/l10n

A helper library to assist in localizing subprocesses spun up by VS Code extensions


Version published
Weekly downloads
873K
decreased by-3.47%
Maintainers
7
Weekly downloads
 
Created

What is @vscode/l10n?

@vscode/l10n is a localization library designed to help developers internationalize their Visual Studio Code extensions. It provides tools to manage and use localized strings within extensions, making it easier to support multiple languages.

What are @vscode/l10n's main functionalities?

Loading Localized Strings

This feature allows you to load localized strings based on the user's locale. The code sample demonstrates how to configure the locale and messages, and then use the localized string in a Visual Studio Code extension.

const vscode = require('vscode');
const l10n = require('@vscode/l10n');

async function activate(context) {
  await l10n.config({
    locale: 'en',
    messages: {
      'hello': 'Hello, World!'
    }
  });

  const message = l10n.t('hello');
  vscode.window.showInformationMessage(message);
}

exports.activate = activate;

Dynamic Locale Switching

This feature allows dynamic switching of locales within the extension. The code sample shows how to switch from English to Spanish and update the localized string accordingly.

const vscode = require('vscode');
const l10n = require('@vscode/l10n');

async function activate(context) {
  await l10n.config({
    locale: 'en',
    messages: {
      'hello': 'Hello, World!'
    }
  });

  vscode.commands.registerCommand('extension.switchLocale', async () => {
    await l10n.config({
      locale: 'es',
      messages: {
        'hello': '¡Hola, Mundo!'
      }
    });
    const message = l10n.t('hello');
    vscode.window.showInformationMessage(message);
  });
}

exports.activate = activate;

Using Placeholders in Localized Strings

This feature supports placeholders in localized strings, allowing dynamic content to be inserted. The code sample demonstrates how to use a placeholder in a localized string and replace it with a variable.

const vscode = require('vscode');
const l10n = require('@vscode/l10n');

async function activate(context) {
  await l10n.config({
    locale: 'en',
    messages: {
      'greeting': 'Hello, {0}!'
    }
  });

  const name = 'John';
  const message = l10n.t('greeting', name);
  vscode.window.showInformationMessage(message);
}

exports.activate = activate;

Other packages similar to @vscode/l10n

FAQs

Package last updated on 10 Dec 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc