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;
``