Raiondesu / intl-schematic

Yet another simple and lightweight i18n library
https://www.npmjs.com/package/intl-schematic
MIT License
3 stars 0 forks source link
formatting-text i18n intl l10n localization schema schematic typescript typescript-library

intl-schematic

Stupidly simple, incredibly tiny, blazingly fast. This is a tiny framework-agnostic i18n library (1-3kb, zero-dependency)\ that allows to localize and format strings\ while sparingly using the browser-standard [`Intl` API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl). `npm i -s intl-schematic` You can also install a nightly build\ [directly from github](#install-from-github) For more usage examples, see\ the [main package readme](/packages/core/README.md) [List of packages](#packages)

Simple usage example

import { createTranslator } from 'intl-schematic';

// Define a translation document factory
const getDocument = () => ({
  "hello": "Hello, World!"
});

// Create a translator function (`t()`)
const t = createTranslator(getDocument);

// Use the translator function
console.log(t('hello')); // `Hello, World!`

Features

Why

I've grown frustrated with current implementations of popular l10n/i18n libraries, many of which:

This library will try to avoid these common pitfalls, while retaining a small size and good performance.

No-goals

Even though custom plugins can do literally anything with keys, values and translation documents,\ the core library will not support:

Contributing

To contribute, create a branch and make a PR to main, or create an issue.

Packages

This project utilizes a monorepo structure based on npm workspaces,\ with the main package being, of course, intl-schematic.

Full list of packages at the moment:

Local development

To develop locally, simply clone, and run the following in the root directory:

npm i -ws

The project uses TypeScript v5.3+

Build

Simply run

npm run build

to rebuild any changed packages.

Install from github

In order to evaluate and test the newest version that is yet to be released on npm, simply install from github:

npm install 'https://gitpkg.now.sh/Raiondesu/intl-schematic/packages/core?main'

⚠ Nightly builds are unstable and may be broken βš