@itsnep/tl
v1.0.0
Published
Simple fully type-safe translation library for TypeScript.
Maintainers
Readme
@itsnep/tl
Simple fully type-safe translation library for TypeScript.
Installation
npm install @itsnep/tl
# or
pnpm add @itsnep/tl
# or
yarn add @itsnep/tlExample usage
import { TL } from '@itsnep/tl';
// Create message. make sure to use **const** in order for typing to work correctly.
export const validation = {
required: '{attribute} is required.',
numeric: '{attribute} must be a number.',
unique: '{attribute} already used.',
min: {
numeric: '{attribute} must be atleast {min}.',
file: '{attribute} must be atleast {min} kilobyte.'
},
...
} as const; // <- **const** is required
// Create translation instance
export const tl = TL({ validation });
// Usage
console.log(tl('validation.required', { attribute: 'Email' })); // Output: "Email is required."License
MIT
