The content of this page was translated using an AI.

    See the last version of the original content in English

    Intlayer Configuration Documentation

    Overview

    Intlayer configuration files allow customisation of various aspects of the plugin, such as internationalisation, middleware, and content handling. This document provides a detailed description of each property in the configuration.


    Configuration File Support

    Intlayer accepts JSON, JS, MJS, and TS configuration file formats:

    • intlayer.config.ts
    • intlayer.config.js
    • intlayer.config.json
    • intlayer.config.cjs
    • intlayer.config.mjs
    • .intlayerrc

    Example config file

    intlayer.config.ts
    import { Locales, type IntlayerConfig } from "intlayer";const config: IntlayerConfig = {  internationalisation: {    locales: [Locales.ENGLISH],  },  content: {    typesDir: "content/types",  },  middleware: {    noPrefix: false,  },};export default config;

    Configuration Reference

    The following sections describe the various configuration settings available for Intlayer.


    Internationalisation Configuration

    Defines settings related to internationalisation, including available locales and the default locale for the application.

    Properties

    • locales:

      • Type: string[]
      • Default: ['en']
      • Description: The list of supported locales in the application.
      • Example: ['en', 'fr', 'es']
    • requiredLocales:
      • Type: string[]
      • Default: []
      • Description: The list of required locales in the application.
      • Example: []
      • Note: If empty, all locales are required in strict mode.
      • Note: Ensure required locales are also defined in the locales field.
    • strictMode:

      • Type: string
      • Default: inclusive
      • Description: Ensure strong implementations of internationalised content using TypeScript.
      • Note: If set to "strict", the translation t function will require each declared locale to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.
      • Note: If set to "inclusive", the translation t function will require each declared locale to be defined. If one locale is missing, it will throw a warning. But it will accept if a locale is not declared in your config, but exists.
      • Note: If set to "loose", the translation t function will accept any existing locale.
    • defaultLocale:

      • Type: string
      • Default: 'en'
      • Description: The default locale used as a fallback if the requested locale is not found.
      • Example: 'en'
      • Note: This is used to determine the locale when none is specified in the URL, cookie, or header.

    Editor Configuration

    Defines settings related to the integrated editor, including server port and active status.

    Properties

    • applicationURL:

      • Type: string
      • Default: http://localhost:3000
      • Description: The URL of the application. Used to restrict the origin of the editor for security reasons.
      • Example:
        • 'http://localhost:3000'
        • 'https://example.com'
        • process.env.INTLAYER_EDITOR_URL
      • Note: The URL of the application. Used to restrict the origin of the editor for security reasons. If set to '*', the editor is accessible from any origin.
    • port:

      • Type: number
      • Default: 8000
      • Description: The port used by the visual editor server.
    • editorURL:

      • Type: string
      • Default: 'http://localhost:8000'
      • Description: The URL of the editor server. Used to restrict the origin of the editor for security reasons.
        • 'http://localhost:3000'
        • 'https://example.com'
        • process.env.INTLAYER_EDITOR_URL
      • Note: The URL of the editor server to reach from the application. Used to restrict the origins that can interact with the application for security reasons. If set to '*', the editor is accessible from any origin. Should be set if port is changed, or if the editor is hosted on a different domain.
    • cmsURL:

      • Type: string
      • Default: 'https://intlayer.org'
      • Description: The URL of the Intlayer CMS.
      • Example: 'https://intlayer.org'
      • Note: The URL of the Intlayer CMS.
    • backendURL:

      • Type: string
      • Default: https://back.intlayer.org
      • Description: The URL of the backend server.
      • Example: http://localhost:4000
    • enabled:

      • Type: boolean
      • Default: true
      • Description: Indicates if the application interacts with the visual editor.
      • Example: process.env.NODE_ENV !== 'production'
      • Note: If true, the editor will be able to interact with the application. If false, the editor will not be able to interact with the application. In any case, the editor can only be enabled by the visual editor. Disabling the editor for specific environments is a way to enforce security.
    • clientId:

      • Type: string | undefined
      • Default: undefined
      • Description: clientId and clientSecret allow the Intlayer packages to authenticate with the backend using OAuth2 authentication. An access token is used to authenticate the user related to the project. To get an access token, go to /dashboard/project and create an account.
      • Example: true
      • Note: Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.
    • clientSecret:

      • Type: string | undefined
      • Default: undefined
      • Description: clientId and clientSecret allow the Intlayer packages to authenticate with the backend using OAuth2 authentication. An access token is used to authenticate the user related to the project. To get an access token, go to /dashboard/project and create an account.
      • Example: true
      • Note: Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.
    • hotReload:

      • Type: boolean
      • Default: false
      • Description: Indicates if the application should hot reload the locale configurations when a change is detected.
      • Example: true
      • Note: For example, when a new dictionary is added or updated, the application will update the content to display on the page.
      • Note: Because the hot reloading needs a continuous connection to the server, it is only available for clients of the enterprise plan.
    • dictionaryPriorityStrategy:

      • Type: string
      • Default: 'local_first'
      • Description: The strategy to prioritise dictionaries in the case of both local and distant dictionaries being present. If set to 'distant_first', the application will prioritise distant dictionaries over local dictionaries. If set to 'local_first', the application will prioritise local dictionaries over distant dictionaries.
      • Example: 'distant_first'

    Middleware Configuration

    Settings that control middleware behaviour, including how the application handles cookies, headers, and URL prefixes for locale management.

    Properties

    • headerName:

      • Type: string
      • Default: 'x-intlayer-locale'
      • Description: The name of the HTTP header used to determine the locale.
      • Example: 'x-custom-locale'
      • Note: This is useful for API-based locale determination.


    • cookieName:

      • Type: string
      • Default: 'intlayer-locale'
      • Description: The name of the cookie used to store the locale.
      • Example: 'custom-locale'
      • Note: Used to persist the locale across sessions.
    • prefixDefault:

      • Type: boolean
      • Default: true
      • Description: Whether to include the default locale in the URL.
      • Example: false
      • Note: If false, URLs for the default locale will not have a locale prefix.
    • basePath:

      • Type: string
      • Default: ''
      • Description: The base path for the application URLs.
      • Example: '/my-app'
      • Note: This affects how URLs are constructed for the application.
    • serverSetCookie:

      • Type: string
      • Default: 'always'
      • Description: Rule for setting the locale cookie on the server.
      • Options: 'always', 'never'
      • Example: 'never'
      • Note: Controls whether the locale cookie is set on every request or never.
    • noPrefix:

      • Type: boolean
      • Default: false
      • Description: Whether to omit the locale prefix from URLs.
      • Example: true
      • Note: If true, URLs will not contain locale information.

    Content Configuration

    Settings related to content handling within the application, including directory names, file extensions, and derived configurations.

    Properties

    • watch:

      • Type: boolean
      • Default: process.env.NODE_ENV === 'development'
      • Description: Indicates if Intlayer should watch for changes in the content declaration files in the app to rebuild the related dictionaries.
    • fileExtensions:

      • Type: string[]
      • Default: ['.content.ts', '.content.js', '.content.cjs', '.content.mjs', '.content.json', '.content.tsx', '.content.jsx']
      • Description: File extensions to look for when building dictionaries.
      • Example: ['.data.ts', '.data.js', '.data.json']
      • Note: Customising file extensions can help avoid conflicts.
    • baseDir:

      • Type: string
      • Default: process.cwd()
      • Description: The base directory for the project.
      • Example: '/path/to/project'
      • Note: This is used to resolve all Intlayer-related directories.
    • dictionaryOutput:

      • Type: string[]
      • Default: ['intlayer']
      • Description: The type of dictionary output to use, e.g., 'intlayer' or 'i18next'.
    • contentDir:

      • Type: string[]
      • Default: ['src']
      • Description: The directory path where content is stored.
    • dictionariesDir:

      • Type: string
      • Default: '.intlayer/dictionaries'
      • Description: The directory path for storing intermediate or output results.
    • moduleAugmentationDir:

      • Type: string
      • Default: '.intlayer/types'
      • Description: Directory for module augmentation, allowing better IDE suggestions and type checking.
      • Example: 'intlayer-types'
      • Note: Be sure to include this in tsconfig.json.
    • unmergedDictionariesDir:

      • Type: string
      • Default: '.intlayer/unmerged_dictionary'
      • Description: The directory for storing unmerged dictionaries.
      • Example: 'translations'
    • dictionariesDir:

      • Type: string
      • Default: '.intlayer/dictionary'
      • Description: The directory for storing localisation dictionaries.
      • Example: 'translations'
    • i18nextResourcesDir:

      • Type: string
      • Default: 'i18next_dictionary'
      • Description: The directory for storing i18n dictionaries.
      • Example: 'translations'
      • Note: Ensure this directory is configured for the i18next output type.
    • typesDir:

      • Type: string
      • Default: 'types'
      • Description: The directory for storing dictionary types.
      • Example: 'intlayer-types'
    • mainDir:

      • Type: string
      • Default: 'main'
      • Description: The directory where main application files are stored.
      • Example: 'intlayer-main'
    • excludedPath:

      • Type: string[]
      • Default: ['node_modules']
      • Description: Directories excluded from content search.
      • Note: This setting is not yet used, but planned for future implementation.

    Logger Configuration

    Settings that control the logger, including the prefix to use.

    Properties

    • mode:

      • Type: string
      • Default: default
      • Description: Indicates the mode of the logger.
      • Options: default, verbose, disabled
      • Example: default
      • Note: The mode of the logger. Verbose mode will log more information, but can be used for debugging purposes. Disabled mode will disable the logger.
    • prefix:

      • Type: string
      • Default: '[intlayer] '
      • Description: The prefix of the logger.
      • Example: '[my custom prefix] '
      • Note: The prefix of the logger.

    AI Configuration

    Settings that control the AI features of Intlayer, including the provider, model, and API key.

    This configuration is optional if you're registered on the Intlayer Dashboard using an access key. Intlayer will automatically manage the most efficient and cost-effective AI solution for your needs. Using the default options ensures better long-term maintainability as Intlayer continuously updates to use the most relevant models.

    If you prefer to use your own API key or specific model, you can define your custom AI configuration. This AI configuration will be used globally across your Intlayer environment. CLI commands will use these settings as defaults for the commands (e.g. fill), as well as the SDK, Visual Editor, and CMS. You can override these default values for specific use cases using command parameters.

    Intlayer supports multiple AI providers for enhanced flexibility and choice. Currently supported providers are:

    • OpenAI (default)
    • Anthropic Claude
    • Mistral AI
    • DeepSeek
    • Google Gemini
    • Meta Llama

    Properties

    • provider:

      • Type: string
      • Default: 'openai'
      • Description: The provider to use for the AI features of Intlayer.
      • Options: 'openai', 'anthropic', 'mistral', 'deepseek', 'gemini'
      • Example: 'anthropic'
      • Note: Different providers may require different API keys and have different pricing models.
    • model:

      • Type: string
      • Default: None
      • Description: The model to use for the AI features of Intlayer.
      • Example: 'gpt-4o-2024-11-20'
      • Note: The specific model to use varies by provider.
    • temperature:

      • Type: number
      • Default: None
      • Description: The temperature controls the randomness of the AI's responses.
      • Example: 0.1
      • Note: A higher temperature will make the AI more creative and less predictable.
    • apiKey:

      • Type: string
      • Default: None
      • Description: Your API key for the selected provider.
      • Example: process.env.OPENAI_API_KEY
      • Note: Important: API keys should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.
    • applicationContext:

      • Type: string
      • Default: None
      • Description: Provides additional context about your application to the AI model, helping it generate more accurate and contextually appropriate translations. This can include information about your app's domain, target audience, tone, or specific terminology.

    If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.

    GitHub link to the documentation