Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update Solid useIntlayer API usage to direct property access"v8.9.004/05/2026
- "Initial history"v8.4.1031/03/2026
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Translate your Vanilla JS website using Intlayer | Internationalisation (i18n)
Table of Contents
Why Intlayer over alternatives?
Compared to main solutions like i18next or i18n.js, Intlayer is a solution that comes with integrated optimizations such as:
Intlayer is optimized to work perfectly with Vanilla JavaScript by offering framework-agnostic content management, TypeScript support, and all the features needed for scaling internationalization (i18n).
Instead of loading massive JSON files into your pages, load only the necessary content. Intlayer helps reduce your bundle and page sizes by up to 50%.
Scoping your application's content facilitates maintenance for large-scale applications. You can duplicate or delete a single feature folder without the mental burden of reviewing your entire content codebase. Additionally, Intlayer is fully typed to ensure your content's accuracy.
Co-locating content reduces the context needed by Large Language Models (LLMs). Intlayer also comes with a suite of tools, such as a CLI to test for missing translations,LSP, MCP, and agent skills, to make the developer experience (DX) even smoother for AI agents.
Use automation to translate in your CI/CD pipeline using the LLM of your choice at the cost of your AI provider. Intlayer also offers a compiler to automate content extraction, as well as a web platform to help translate in the background.
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimizes your content loading at build time.
More than just an i18n solution, Intlayer provides an self-hosted visual editor and a full CMS to help you manage your multilingual content in real-time, making collaboration with translators, copywriters, and other team members seamless. Content can be stored locally and/or remotely.
Step-by-Step Guide to Set Up Intlayer in a Vanilla JS Application
Install Dependencies
Install the necessary packages using npm:
intlayer The core package that provides internationalisation tools for configuration management, translation, content declaration, transpilation, and CLI commands.
vanilla-intlayer The package that integrates Intlayer with plain JavaScript / TypeScript applications. It provides a pub/sub singleton (
IntlayerClient) and callback-based helpers (useIntlayer,useLocale, etc.) so any part of your app can react to locale changes without depending on a UI framework.
The
intlayer standaloneCLI's bundling export creates an optimised build through tree-shaking for unused packages, locales, and non-essential logic (like redirects or prefixes) specific to your configuration.Configuration of your project
Create a config file to configure the languages of your application:
Through this configuration file, you can set up localised URLs, middleware redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the configuration documentation.
Import the bundle in your HTML
Once you have generated the
intlayer.jsbundle, you can import it in your HTML file:The bundle exposes
IntlayerandVanillaIntlayeras global objects on thewindow.Bootstrap Intlayer in your entry point
In your
src/main.js, callinstallIntlayer()before any content is rendered so that the global locale singleton is ready.If you also want to use the markdown renderer, call
installIntlayerMarkdown():Declare Your Content
Create and manage your content declarations to store translations:
Your content declarations can be defined anywhere in your application as soon as they are included in the
contentDirdirectory (by default,./src). And match the content declaration file extension (by default,.content.{json,ts,tsx,js,jsx,mjs,cjs,md,mdx,yaml,yml}).For more details, refer to the content declaration documentation.
Use Intlayer in Your JavaScript
The
window.VanillaIntlayerobject provides API helpers:useIntlayer(key, locale?)returns the translated content for a given key.Access leaf values as strings by wrapping them in
String(), which calls the node'stoString()method and returns the translated text.When you need the value for a native HTML attribute (e.g.
alt,aria-label), use.valuedirectly:Change the language of your content
OptionalTo change the language of your content, use the
setLocalefunction exposed byuseLocale.Switch the HTML Language and Direction Attributes
OptionalUpdate the
<html>tag'slanganddirattributes to match the current locale for accessibility and SEO.Lazy-load dictionaries per locale
OptionalIf you want to lazy-load dictionaries per locale, you can use
useDictionaryDynamic. This is useful if you don't want to bundle all translations in the initialintlayer.jsfile.Note:
useDictionaryDynamicrequires the dictionaries to be available as separate ESM files. This approach is typically used if you have a web server serving the dictionaries.
Configure TypeScript
Ensure your TypeScript configuration includes the autogenerated types.
VS Code Extension
To improve your development experience with Intlayer, you can install the official Intlayer VS Code Extension.
Install from the VS Code Marketplace
This extension provides:
- Autocompletion for translation keys.
- Real-time error detection for missing translations.
- Inline previews of translated content.
- Quick actions to easily create and update translations.
For more details on how to use the extension, refer to the Intlayer VS Code Extension documentation.
Go Further
To go further, you can implement the visual editor or externalise your content using the CMS.