A simple and lightweight way to integrate internationalization on a small web site project.
The "s" in si18n stands for simple.
| Fast | Lightweight | No dependencies | Easy to use |
|---|---|---|---|
| Yes | Yes | Yes | Yes |
npm i si18n.jsthen use the browser-ready Si18n class:
import Si18n from "si18n.js";yarn add si18n.js<!-- jsDelivr (recommended) -->
<script type="module" src="https://cdn.jsdelivr.net/npm/si18n.js@latest/si18n.js"></script>
<!-- minified -->
<script type="module" src="https://cdn.jsdelivr.net/npm/si18n.js@latest/si18n.min.js"></script>
<!-- UNPKG -->
<script type="module" src="https://unpkg.com/si18n.js@latest/si18n.js"></script>
<script type="module" src="https://unpkg.com/si18n.js@latest/si18n.min.js"></script>npm i si18n.jsthen use the dedicated Node.js export:
const { Si18nNode: Si18n } = require("si18n.js/node");npm i si18n.jsthen import the subpath that matches your runtime:
import Si18nBrowser from "si18n.js/browser";
import Si18nNode from "si18n.js/node";
import { Si18nCore } from "si18n.js/core";npm i si18n.js reactClient-side provider and hook:
"use client";
import Si18nBrowser from "si18n.js/browser";
import { Si18nProvider, useTranslation } from "si18n.js/react";
const i18n = new Si18nBrowser();
function Content() {
const { t, locale, setLocale } = useTranslation();
return (
<>
<h1>{t("title")}</h1>
<button onClick={() => void setLocale(locale === "en" ? "fr" : "en")}>Switch</button>
</>
);
}
export default function App() {
return (
<Si18nProvider
i18n={i18n}
options={{
locales: {
en: { title: "Hello" },
fr: { title: "Bonjour" }
},
lang: "en",
fallbackLang: "en"
}}
>
<Content />
</Si18nProvider>
);
}Server-side helper:
import { createServerTranslator } from "si18n.js/react/server";
const { t } = await createServerTranslator({
locales: {
en: { title: "Hello" },
fr: { title: "Bonjour" }
},
lang: "en",
fallbackLang: "en"
});
console.log(t("title"));Note
For detailed usage information, demos, and the full API reference, visit the docs.
The following instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
git clone git@github.com:jdbruxelles/si18n.js.gitnpm install- Run the build process
npm run build- Run tests
npm test- Watch files during development
npm run watchAutomated publishing is handled via GitHub Actions with SLSA build provenance attestation.
To release a new version:
- Update
"version"inpackage.jsonand updateCHANGELOG.md. - Verify tests and tarball contents locally:
npm test npm run pack:check - Commit, push to
main, and create a GitHub Release with a matching tag (e.g.v2.0.0). - The release workflow automatically builds, tests, verifies tag parity, and publishes to npm with provenance.
For configuration details and emergency manual publishing, see .github/workflows/README.md.
For the server, you can use any server you want, but I recommend using http-server. It's a simple zero-configuration command-line http server. I personally use the python http.server or the server provided by netlify-cli to work locally.
Contributions are always welcome! For major changes, please open an issue first to discuss what you would like to change.
You can help translate the application by using Crowdin.
All translations are stored in the website/locales directory. Under no circumstances should you edit the files in this directory, except for the fr.json file which is the source language for the translations.
Translations will be available on the app if they exceed a certain threshold of completion (currently 90%).