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

@cloudflare/intl-core

Package Overview
Dependencies
Maintainers
18
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/intl-core

> @cloudflare/intl-core

  • 1.0.3
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
increased by11.85%
Maintainers
18
Weekly downloads
 
Created
Source

intl-core

@cloudflare/intl-core

This package provides core utilities for i18n.

Installation

$ npm install @cloudflare/intl-core

Translator

This is a wrapper around the functions of Polyglot.

The main benefit it provides is that it stores various instances of Polyglot for each locale in order to be able to locate translations which are not found in target locale but are found in English locale.

import Translator from '@cloudfalre/intl-core';

const phrases = {
  phrase_key: 'phrase_value',
  second_phrase: 'second_value'
};

const germanPhrases = {
  phrase_key: 'german_value'
};
const translator = new Translator({
  phrases
});

translator.locale(ESupportedLocales.de_DE);
translator.extend(germanPhrases);

translator.t('phrase_key'); //returns german_value since it's found for the german locale
translator.t('second_phrase'); //returns second_value since it was not found in german locale but was found in English locale

makeLoadPhrases

This is a function which takes an object mapping each locale to a function returning a Promise which resolves to the catalog of phrases for that locale.

The main usecase for this is to provide a way to asynchronously load phrases based on locale. You can include an index.ts file inside your locale directory with the following content:

import { makeLoadPhrases, ESupportedLocales } from '@cloudflare/intl-core';

const loadPhrases = makeLoadPhrases({
  [ESupportedLocales.en_US]: () => import('./en-US/phrases.json')
  //...other locales
});

export default loadPhrases;

FAQs

Package last updated on 27 Sep 2018

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