Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@intlify/core-base

Package Overview
Dependencies
Maintainers
2
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intlify/core-base

@intlify/core-base

  • 10.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @intlify/core-base?

@intlify/core-base is a core library for internationalization (i18n) in JavaScript applications. It provides essential functionalities for handling translations, message formatting, and locale management, making it easier to build multilingual applications.

What are @intlify/core-base's main functionalities?

Basic Translation

This feature allows you to define translations for different locales and switch between them. The code sample demonstrates how to create a context with messages in English and French, and how to switch the locale to get the translated message.

const { createCoreContext, translate } = require('@intlify/core-base');

const ctx = createCoreContext({
  locale: 'en',
  messages: {
    en: {
      hello: 'Hello, world!'
    },
    fr: {
      hello: 'Bonjour, le monde!'
    }
  }
});

console.log(translate(ctx, 'hello')); // Output: Hello, world!
ctx.locale = 'fr';
console.log(translate(ctx, 'hello')); // Output: Bonjour, le monde!

Message Formatting

This feature allows you to use placeholders in your messages and replace them with dynamic values. The code sample shows how to define a message with a placeholder and provide a value for it during translation.

const { createCoreContext, translate } = require('@intlify/core-base');

const ctx = createCoreContext({
  locale: 'en',
  messages: {
    en: {
      greeting: 'Hello, {name}!'
    }
  }
});

console.log(translate(ctx, 'greeting', { name: 'Alice' })); // Output: Hello, Alice!

Locale Management

This feature provides the ability to manage the current locale and fallback locales. The code sample demonstrates how to set and get the current locale and how to define a fallback locale.

const { createCoreContext } = require('@intlify/core-base');

const ctx = createCoreContext({
  locale: 'en',
  fallbackLocale: 'fr',
  messages: {
    en: {
      hello: 'Hello, world!'
    },
    fr: {
      hello: 'Bonjour, le monde!'
    }
  }
});

console.log(ctx.locale); // Output: en
ctx.locale = 'fr';
console.log(ctx.locale); // Output: fr

Other packages similar to @intlify/core-base

Keywords

FAQs

Package last updated on 12 Sep 2024

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