Receive notifications about upcoming Intlayer releases
    Creation:2025-08-23Last update:2025-10-29

    Vue.js Internationalization (i18n) with vue-i18n and Intlayer

    Table of Contents

    What is Intlayer?

    Intlayer is an innovative, open-source internationalization library designed to address the shortcomings of traditional i18n solutions. It offers a modern approach to content management in Vue.js and Nuxt applications.

    See a concrete comparison with vue-i18n in our vue-i18n vs. Intlayer blog post.

    Why Combine Intlayer with vue-i18n?

    While Intlayer provides an excellent standalone i18n solution (see our Vue.js integration guide), you might want to combine it with vue-i18n for several reasons:

    1. Existing codebase: You have an established vue-i18n implementation and want to gradually migrate to Intlayer's improved developer experience.
    2. Legacy requirements: Your project requires compatibility with existing vue-i18n plugins or workflows.
    3. Team familiarity: Your team is comfortable with vue-i18n but wants better content management.
    4. Using Intlayer features: You want to use Intlayer features like content declaration, translation automation, testing translations, and more.

    For that, Intlayer can be implemented as an adapter for vue-i18n to help automating your JSON translations in CLI or CI/CD pipelines, testing your translations, and more.

    This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with vue-i18n.


    Step-by-Step Guide to Set Up Intlayer with vue-i18n

    Step 1: Install Dependencies

    Install the necessary packages using your preferred package manager:

    npm install intlayer @intlayer/sync-json-plugin

    Package explanations:

    • intlayer: Core library for content declaration and management
    • @intlayer/sync-json-plugin: Plugin to sync Intlayer content declarations to vue-i18n JSON format

    Step 2: Implement the Intlayer plugin to wrap the JSON

    Create an Intlayer configuration file to define your supported locales:

    If you want to also export JSON dictionaries for vue-i18n, add the syncJSON plugin:

    intlayer.config.ts
    import { Locales, type IntlayerConfig } from "intlayer";import { syncJSON } from "@intlayer/sync-json-plugin";const config: IntlayerConfig = {  internationalization: {    locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],    defaultLocale: Locales.ENGLISH,  },  plugins: [    syncJSON({      source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,    }),  ],};export default config;

    The syncJSON plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.

    If you want to make coexist that JSON with intlayer content declaration files (.content files), Intlayer will proceed this way:

    1. load both JSON and content declaration files and transform them into a intlayer dictionary.2. if there is conflicts between the JSON and the content declaration files, Intlayer will process to the merge of that all dictionaries. Depending of the priority of the plugins, and the one of the content declaration file (all are configurable).

    If changes are made using the CLI to translate the JSON, or using the CMS, Intlayer will update the JSON file with the new translations.

    To see more details about the syncJSON plugin, please refer to the syncJSON plugin documentation.


    (Optional) Step 3: Implement per-component JSON translations

    By default, Intlayer will load, merge and synchronize both JSON and content declaration files. See the content declaration documentation for more details. But if you prefer, using a Intlayer plugin, you can also implement per-component management of JSON localized anywhere in your codebase.

    For that, you can use the loadJSON plugin.

    intlayer.config.ts
    import { Locales, type IntlayerConfig } from "intlayer";import { loadJSON, syncJSON } from "@intlayer/sync-json-plugin";const config: IntlayerConfig = {  internationalization: {    locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],    defaultLocale: Locales.ENGLISH,  },  // Keep your current JSON files in sync with Intlayer dictionaries  plugins: [    /**     * Will load all the JSON files in the src that match the pattern {key}.i18n json     */    loadJSON({      source: ({ key }) => `./src/**/${key}.i18n.json`,      locale: Locales.ENGLISH,      priority: 1, // Ensures these JSON files take precedence over files at `./locales/en/${key}.json`    }),    /**     * Will load, and write the output and translations back to the JSON files in the locales directory     */    syncJSON({      source: ({ key, locale }) => `./src/locales/${locale}/${key}.json`,      priority: 0,    }),  ],};export default config;

    This will load all the JSON files in the src directory that match the pattern {key}.i18n.json and load them as Intlayer dictionaries.


    Git Configuration

    Exclude generated files from version control:

    .gitignore
    # Ignore files generated by Intlayer.intlayerintl

    These files are automatically regenerated during the build process and don't need to be committed to your repository.

    VS Code Extension

    For improved developer experience, install the official Intlayer VS Code Extension:

    Install from the VS Code Marketplace