A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.

Created by Ivan Hofer (1995-2023)
:baby_chick: lightweight (~1kb)\ :ok_hand: easy to use syntax\ :running: fast and efficient\ :safety_vest: prevents you from making mistakes (also in plain JavaScript projects)\ :construction_worker: creates boilerplate code for you\ :speech_balloon: supports plural rules\ :date: allows formatting of values e.g. locale-dependent date or number formats\ :left_right_arrow: supports switch-case statements e.g. for gender-specific output\ :arrow_down: option for asynchronous loading of locales\ :books: supports multiple namespaces\ :stopwatch: supports SSR (Server-Side Rendering)\ :handshake: can be used for frontend, backend and API projects\ :mag: locale-detection for browser and server environments\ :arrows_counterclockwise: import and export translations from/to files or services\ :no_entry: no external dependencies
Click here to see an interactive demo of typesafe-i18n showing some key aspects of the type-checking capabilities of this internationalization library.
typesafe-i18n to your projecttypesafe-i18n add to your bundle sizetypesafe-i18n implemented:keyboard: Run the setup process and automatically detect the config needed
bash
npx typesafe-i18n --setup-auto
or manually configure typesafe-i18n by answering a few questions
bash
npx typesafe-i18n --setup
It didn't work? See here for possible troubleshooting.
:eyes: Take a look at the generated files and it's folder-structure after running npm run typesafe-i18n (or npx typesafe-i18n)
:open_book: Explore the assets
typesafe-i18noffers a lot. Just presscmd + Fto search on this page or see the table of contents that will link you to more specific subpages with more details.
:star: Star this project on GitHub
Thanks! This helps the project to grow.
\
Having trouble setting up typesafe-i18n? Reach out to us via Github Discussions or on Discord.
npm install typesafe-i18n
The changelog of this project can be found here
5.x.x: see the release post4.x.x: see the release post3.x.x: see the release postCurious about what comes next? See this discussion to learn more about the plans for the future of this project.
If you would like to get involved within this project, take a look at this discussion.
The package can be used inside JavaScript and TypeScript applications. You will get a lot of benefits by running the generator since it will create a few wrappers to provide you with full typesafety.
You can use typesafe-i18n in a variety of project-setups:
All you need is inside the generated file i18n-util.ts. You can use the functions in there to create a small wrapper for your application.
Feel free to open a new discussion if you need a guide for a specific framework.
See here if you want to learn how you can use typesafe-i18n to implement your own specific use-case.
The library should work in all modern browsers. It uses some functionality from the Intl namespace. You can see the list of supported browsers here. If you want to support older browsers that don't include these functions, you would need to include a polyfill like intl-pluralrules.
If you want to get the best typesafety features, you will need to use the generator in order to create types and boilerplate code for you
Here you can see some examples where typesafe-i18n can help you:




![typesafe keys in translations](https://raw.githubusercontent.com/ivanhofer/typesafe-i18n/main/assets/05_typesafe-keys-in-tr
$ claude mcp add typesafe-i18n \
-- python -m otcore.mcp_server <graph>