@intl-schematic/plugin-functions
v1.0.0-rc.4
Published
Adds the ability to use plain functions in translation documents.
Downloads
3
Maintainers
Readme
@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');