🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@intl-schematic/plugin-functions

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intl-schematic/plugin-functions

Adds the ability to use plain functions in translation documents.

1.0.0-rc.4
latest
Source
npm
Version published
Maintainers
1
Created
Source

@intl-schematic/plugin-functions

Adds the ability to use plain functions in translation documents.

npm i -s @intl-schematic/plugin-functions

Define a translation document factory

const getDocument = () => ({
  "hello": (name: string) => `Hello, ${name}!`
});

Create a translator function (t())

import { createTranslator } from 'intl-schematic';
import { FunctionsPlugin } from '@intl-schematic/plugin-functions';

// Notice the plugins array parameter
const t = createTranslator(getDocument, [FunctionsPlugin]);

Use the translator function

console.log(t('hello', 'Bob')); // `Hello, Bob!`

// Parameter auto-complete and type-checking!

// TS Error: Argument of type 'number' is not assignable to parameter of type 'string'.
t('hello', 42);

// TS Error: Expected 2 arguments, but got 1.
t('hello');

Keywords

l10n

FAQs

Package last updated on 20 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