@sil/locale
TypeScript icon, indicating that this package has built-in type declarations

0.1.10 • Public • Published

Locale

A clean and simple thing to use translations.

Install

npm install @sil/locale

Usage

Create a file locale.ts in your project. In this file;

In this file you include all your languages, you import your content and define the locales. This will automatically create a state which can be imported/used throughout your project.

import { createLocale } from "@sil/locale";

import EN from "./data/en";
import NL from "./data/nl";
import MT from "./data/mt";

const Languages = {
  AUTO: "auto",
  EN: "EN_uk",
  NL: "NL_nl",
  MT: "MT_mt",
};

const localeData = {
  [Languages.EN]: EN,
  [Languages.NL]: NL,
  [Languages.MT]: MT,
};

const { t, locales, currentLocale, state } = createLocale({
  locales: Languages,
  locale: Languages.AUTO,
  fallbackLocale: Languages.EN,
  messages: localeData,
});

export { t, locales, currentLocale, state };

Example Content file;

const copy = {
    hello: "Hello"
};
export default copy;
``

Package Sidebar

Install

npm i @sil/locale

Weekly Downloads

3

Version

0.1.10

License

MIT

Unpacked Size

195 kB

Total Files

10

Last publish

Collaborators

  • hacobvandipyan
  • silvandiepen