1. Documentation
    2. Packages
    3. intlayer
    4. getConfiguration

    Documentation: getConfiguration Function in intlayer

    Description:

    The getConfiguration function retrieves the entire configuration for the intlayer application by extracting environment variables. This function provides the flexibility to use the same configuration on both the client and server sides, ensuring consistency across the application.


    Parameters:

    The function does not take any parameters. Instead, it uses environment variables for configuration.

    Returns:

    • Type: IntlayerConfig
    • Description: An object containing the complete configuration for intlayer. The configuration includes the following sections:

      • internationalization: Settings related to locales and strict mode.
      • middleware: Settings related to URL and cookie management.
      • content: Settings related to content files, directories, and patterns.
      • editor: Editor-specific configurations.

    See Intlayer configuration documentation for more details.


    Example Usage:

    Retrieving the Full Configuration:

    typescript
    1import { getConfiguration } from "intlayer"; 2 3const config = getConfiguration(); 4console.log(config); 5// Output: 6// { 7// internationalization: { ... }, 8// middleware: { ... }, 9// content: { ... }, 10// editor: { ... } 11// }

    Extracting availableLocales and defaultLocale:

    The internationalization section of the configuration provides locale-related settings such as locales (available locales) and defaultLocale (fallback language).

    typescript
    1const { internationalization, middleware } = getConfiguration(); 2const { locales: availableLocales, defaultLocale } = internationalization; 3const { cookieName } = middleware; 4 5console.log(availableLocales); // Output example: ["en", "fr", "es"] 6console.log(defaultLocale); // Output example: "en" 7console.log(cookieName); // Output: "INTLAYER_LOCALE"

    Notes:

    • Ensure that all required environment variables are correctly set before calling this function. Missing variables will cause errors during initialization.
    • This function can be used on both client and server sides, making it a versatile tool for managing configurations in a unified manner.

    Usage in Applications:

    The getConfiguration function is a cornerstone utility for initializing and managing the configuration of an intlayer application. By providing access to settings like locales, middleware, and content directories, it ensures consistency and scalability across multilingual and content-driven applications.

    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

    In this page