@intl-schematic/plugin-functions
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.4 • Public • Published

@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');

Package Sidebar

Install

npm i @intl-schematic/plugin-functions

Weekly Downloads

1

Version

1.0.0-rc.4

License

MIT

Unpacked Size

6.8 kB

Total Files

9

Last publish

Collaborators

  • raiondesu