### Install Intlayer Dependencies Source: https://intlayer.org/doc/environment/create-react-app Installs the core `intlayer` package for internationalization tools, `react-intlayer` for React integration, and `react-scripts-intlayer` for compatibility with Create React App projects using npm. ```bash npm install intlayer react-intlayer react-scripts-intlayer ``` -------------------------------- ### Install Intlayer Dependencies with npm Source: https://intlayer.org/doc/environment/vite-and-solid This command installs the core Intlayer package, the Solid.js integration package, and the Vite plugin for development. It ensures all necessary libraries are available for setting up an Intlayer project. ```bash npm install intlayer solid-intlayernpm install vite-intlayer --save-dev ``` -------------------------------- ### Install Intlayer Dependencies Source: https://intlayer.org/doc/environment/nextjs/14 This command installs the core `intlayer` package, which provides internationalization tools, and the `next-intlayer` package, which integrates Intlayer with Next.js by offering context providers, hooks, and a Next.js plugin. ```bash npm install intlayer next-intlayer ``` -------------------------------- ### Install and Run Intlayer MCP Server via CLI Source: https://intlayer.org/doc/mcp-server This snippet provides commands to install the Intlayer Model Context Protocol (MCP) server globally using npm or to run it directly using npx. Running with npx is generally recommended as it uses the latest available version without requiring a global installation. ```bash # Install globally npm install -g @intlayer/mcp # Or use directly with npx (recommended) npx @intlayer/mcp ``` -------------------------------- ### Update React Scripts for Intlayer Source: https://intlayer.org/doc/environment/create-react-app Modifies the `scripts` section within the `package.json` file to replace standard `react-scripts` with `react-scripts-intlayer` for `build` and `start` commands, and adds a `transpile` command for `intlayer`. ```json "scripts": { "build": "react-scripts-intlayer build", "start": "react-scripts-intlayer start", "transpile": "intlayer build" }, ``` -------------------------------- ### Installing Intlayer SWC Plugin for Bundle Optimization Source: https://intlayer.org/doc/environment/nextjs/14 This command installs the `@intlayer/swc` package as a development dependency. This plugin optimizes bundle size by intelligently replacing `useIntlayer` calls, ensuring dictionaries are only included where used, specifically for Next.js 13+ applications. ```Bash npm install @intlayer/swc --save-dev ``` -------------------------------- ### Install Intlayer Dependencies with npm Source: https://intlayer.org/doc/environment/vite-and-react This command installs the core Intlayer package, the React integration package, and the Vite plugin for development. These packages are essential for setting up internationalization in a React application using Vite. ```bash npm install intlayer react-intlayernpm install vite-intlayer --save-dev ``` -------------------------------- ### Install Intlayer Dependencies for Nuxt.js Source: https://intlayer.org/doc/environment/nuxt-and-vue Installs the necessary npm packages: `intlayer` (core internationalization tools), `vue-intlayer` (Vue integration), and `nuxt-intlayer` (Nuxt module for automatic setup and locale management). This is the foundational step for setting up Intlayer in your project. ```bash npm install intlayer vue-intlayernpm install --save-dev nuxt-intlayer ``` -------------------------------- ### next-intlayer Providers and Hooks Source: https://intlayer.org/doc/environment/nextjs/14 Documentation for key components and hooks provided by the `next-intlayer` library for managing localization context in Next.js applications. ```APIDOC IntlayerClientProvider: - Purpose: Provides the locale to client-side components. - Placement: Can be placed in any parent component, but recommended in the layout for efficiency and consistent localization context across pages. - Benefit: Avoids reinitialization for every page, improving performance. IntlayerServerProvider: - Purpose: Provides the locale to server children. - Placement: Cannot be set in the layout due to React's cache mechanism for per-request data stores. Placing it in a shared layout would break isolation and prevent correct propagation of server context values to server components. useIntlayer(contentId: string, locale?: string): - Purpose: A hook used to access content dictionaries. - Parameters: - contentId: A string identifier for the content declaration to retrieve. - locale (optional): The specific locale to use for content retrieval. If not provided, the current context locale is used. - Usage: Call the hook with the content declaration ID to get the localized content object. - Example: const content = useIntlayer("page", locale); const content = useIntlayer("client-component-example"); - Special Case: When using content in string attributes (e.g., `alt`, `title`, `href`), you must access the `.value` property of the content object (e.g., `content.image.value`). ``` -------------------------------- ### Install Intlayer Dependencies for Lynx and React Source: https://intlayer.org/doc/environment/lynx-and-react This command installs the essential Intlayer packages required to enable internationalization features within your Lynx and React project. It includes the core 'intlayer' library, the 'react-intlayer' integration for React, and 'lynx-intlayer' for Lynx-specific functionalities. ```bash npm install intlayer react-intlayer lynx-intlayer ``` -------------------------------- ### Install Intlayer Dependencies for React Native Source: https://intlayer.org/doc/environment/react-native-and-expo This command installs the core `intlayer` and `react-intlayer` packages required for internationalization functionality in your React Native project. Additionally, `react-native-intlayer` is installed as a development dependency, providing specific React Native integrations. ```Bash npm install intlayer react-intlayer npm install --save-dev react-native-intlayer ``` -------------------------------- ### Localized URL Examples Source: https://intlayer.org/doc/environment/vite-and-preact Illustrates how URLs are structured for different locales, showing a non-prefixed default locale and prefixed localized routes for Spanish (es) and French (fr). These examples demonstrate the desired output of the localized routing setup. ```plaintext - https://example.com/about- https://example.com/es/about- https://example.com/fr/about ``` -------------------------------- ### Install vite-intlayer package via npm Source: https://intlayer.org/doc/packages/vite-intlayer Installs the `vite-intlayer` package using npm, which provides essential functionalities for internationalization within Vite applications. ```bash npm install vite-intlayer ``` -------------------------------- ### Install Intlayer and Next.js Integration Source: https://intlayer.org/doc/environment/nextjs/next-with-Page-Router Installs the core `intlayer` package for internationalization features and `next-intlayer` for Next.js integration. These packages enable configuration management, translation, transpilation, and Next.js-specific internationalization hooks and middleware. ```bash npm install intlayer next-intlayer ``` -------------------------------- ### Intlayer CLI SDK: Installation and Usage Source: https://intlayer.org/doc/concept/cli This section details how to install the Intlayer CLI SDK as a development dependency and provides an example of its programmatic usage in TypeScript. The SDK exposes functions corresponding to the CLI commands, allowing developers to integrate Intlayer functionalities directly into their applications or scripts. ```bash npm install @intlayer/cli --save-dev ``` ```ts import { push, pull, fill, build, docTranslate, docReview, } from "@intlayer/cli"; push(); pull(); fill(); build(); docTranslate(); docReview(); ``` -------------------------------- ### Install Intlayer Dependencies with npm Source: https://intlayer.org/doc/environment/vite-and-svelte This command installs the core Intlayer package, the Svelte integration package, and the Vite integration package as a development dependency. These packages are essential for setting up internationalization in a project. ```bash npm install intlayer svelte-intlayernpm install vite-intlayer --save-dev ``` -------------------------------- ### ChatGPT MCP Server Configuration Source: https://intlayer.org/doc/mcp-server This API documentation outlines the steps and parameters required to configure the Intlayer MCP server within the ChatGPT environment. It details the fields to be filled in the prompt dashboard to establish a connection to the remote SSE server. ```APIDOC ChatGPT MCP Server Configuration: URL: https://mcp.intlayer.org - Description: The endpoint for the remote Intlayer MCP server. - Type: string - Constraint: Must be a valid URL. Label: Intlayer MCP Server - Description: A user-friendly name for the server configuration within ChatGPT. - Type: string Name: intlayer-mcp-server - Description: A unique identifier for the server configuration. - Type: string Authentication: None - Description: Specifies the authentication method required for connecting to the server. - Type: string - Constraint: Currently, no authentication is required for the public remote server. ``` -------------------------------- ### Intlayer Library Hooks and Utilities for Locale Management Source: https://intlayer.org/doc/environment/create-react-app Reference for key hooks and utility functions from the `react-intlayer` and `intlayer` libraries, essential for managing application locales, generating localized URLs, and retrieving locale-specific information. ```APIDOC useLocale hook (from react-intlayer): - Purpose: Provides access to the current locale, available locales, and a function to change the locale. - Parameters: - `options`: An object with configuration options. - `onLocaleChange`: (Optional) A callback function `(locale: string) => void` that is executed when the locale changes. Useful for side effects like updating the URL. - Returns: An object containing: - `locale`: The currently active locale string. - `availableLocales`: An array of available locale strings. - `setLocale`: A function `(newLocale: string) => void` to programmatically change the locale. getLocaleName hook (from intlayer): - Purpose: Retrieves the human-readable name of a locale. - Parameters: - `localeCode`: The locale code (e.g., 'en', 'fr', 'es'). - `displayLocaleCode`: (Optional) The locale in which the name should be displayed (defaults to the current application locale). - Returns: A string representing the locale's name (e.g., 'English', 'Français'). getLocalizedUrl hook (from intlayer): - Purpose: Constructs a URL path that includes the specified locale. - Parameters: - `path`: The base URL path (e.g., '/about', '/contact?param=value'). - `localeCode`: The target locale code to include in the URL. - Returns: A string representing the localized URL path (e.g., '/fr/about'). getHTMLTextDir hook (from intlayer): - Purpose: Determines the text direction (LTR or RTL) for a given locale. - Parameters: - `localeCode`: The locale code. - Returns: A string, either 'ltr' (left-to-right) or 'rtl' (right-to-left). ``` -------------------------------- ### Install Intlayer SWC Plugin for Bundle Optimization Source: https://intlayer.org/doc/environment/nextjs/next-with-Page-Router This command installs the `@intlayer/swc` package as a development dependency. This plugin optimizes bundle size by intelligently replacing `useIntlayer` calls, ensuring dictionaries are only included where needed. It is currently experimental and requires Next.js 13 or above. ```Bash npm install @intlayer/swc --save-dev ``` -------------------------------- ### Internationalization Best Practices: HTML Attributes Source: https://intlayer.org/doc/environment/create-react-app Documentation for essential HTML attributes (`lang`, `dir`, `hrefLang`, `aria-current`) that are crucial for proper internationalization, accessibility, and SEO in multi-language web applications. ```APIDOC hrefLang attribute: - Applies to: `` and `` elements. - Purpose: Indicates the language of the linked document or the target URL. Used by search engines to serve localized content. - Example: `Français` lang attribute: - Applies to: Any HTML element, commonly `` or ``. - Purpose: Specifies the primary language of the element's content. Essential for screen readers and search engines. - Example: `` or `

Bonjour

` dir attribute: - Applies to: Any HTML element. - Purpose: Specifies the text direction of the element's content (left-to-right 'ltr' or right-to-left 'rtl'). Crucial for languages like Arabic or Hebrew. - Example: `` aria-current attribute: - Applies to: Elements that represent the current item within a set (e.g., current page in pagination, current step in a wizard). - Purpose: Indicates the current item in a navigation or selection context for assistive technologies. - Values: 'page', 'step', 'location', 'date', 'time', 'true', 'false'. - Example: `About Us` ``` -------------------------------- ### Configure Intlayer MCP Local Server in Cursor Source: https://intlayer.org/doc/mcp-server This JSON configuration snippet sets up the Intlayer Model Context Protocol (MCP) server in Cursor using the local stdio transport method. It specifies `npx` as the command to launch the `@intlayer/mcp` package, ensuring the latest available version is used. ```json { "mcpServers": { "intlayer": { "command": "npx", "args": ["-y", "@intlayer/mcp"] } } } ``` -------------------------------- ### Intlayer Next.js Integration API Source: https://intlayer.org/doc/environment/nextjs/14 This section details the key functions provided by `next-intlayer` for integrating Intlayer into a Next.js application, including the plugin for Next.js configuration and the middleware for locale detection and management. ```APIDOC withIntlayer(nextConfig: NextConfig): Promise - Description: A Next.js plugin function that integrates Intlayer with the Next.js build process. - Parameters: - nextConfig: The existing Next.js configuration object. - Returns: A Promise that resolves to the modified Next.js configuration object. - Usage: - Ensures content declaration files are built and monitored. - Defines Intlayer environment variables for Webpack/Turbopack. - Provides aliases for performance optimization. - Guarantees compatibility with Next.js Server Components. intlayerMiddleware: Function - Description: A middleware function designed for Next.js applications to handle locale detection and redirection. - Parameters: None (used directly as a middleware export). - Usage: - Detects the user's preferred locale (e.g., from browser settings or cookies). - Redirects users to the appropriate localized URL as defined in `intlayer.config.ts`. - Can save the user's preferred locale in a cookie. - Typically exported as `middleware` from `src/middleware.ts`. config.matcher: string - Description: A configuration property used with Next.js middleware to specify the paths that the middleware should apply to. - Type: string (regular expression pattern) - Usage: - Example: `"/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)"` - This pattern excludes API routes, static files, and internal Next.js paths from middleware processing. ``` -------------------------------- ### Nuxt Localized Page Component Example Source: https://intlayer.org/doc/environment/nuxt-and-vue Demonstrates a basic Vue component (`pages/about.vue`) that utilizes the `useIntlayer` composable from `vue-intlayer` to fetch and display localized content, such as titles and descriptions. ```Vue ``` -------------------------------- ### Integrate Intlayer Content in React Component Source: https://intlayer.org/doc/environment/create-react-app Demonstrates how to use the `IntlayerProvider` to wrap your application and the `useIntlayer` hook within a React component (`src/App.tsx`) to access and display the internationalized content declared previously. ```typescript import logo from "./logo.svg";import "./App.css";import type { FC } from "react";import { IntlayerProvider, useIntlayer } from "react-intlayer";const AppContent: FC = () => { const content = useIntlayer("app"); return (
logo {content.getStarted} {content.reactLink.content}
); }; const App: FC = () => ( ); export default App; ``` -------------------------------- ### intlayer React Hooks and Utility Functions Source: https://intlayer.org/doc/environment/vite-and-react Comprehensive documentation for key `intlayer` and `react-intlayer` hooks and utility functions used for managing locales, generating localized URLs, and determining text direction in internationalized React applications. ```APIDOC useLocale hook: - Purpose: Provides access to the current locale, available locales, and a function to change the locale within a React component. - Parameters: - `options`: An object with optional properties. - `onLocaleChange`: (locale: string) => void - A callback function executed when the locale changes, useful for side effects like updating the URL. - Returns: - `locale`: string - The currently active locale. - `availableLocales`: string[] - An array of all configured available locales. - `setLocale`: (newLocale: string) => void - A function to programmatically change the current locale. getLocaleName hook: - Purpose: Retrieves the human-readable name for a given locale, optionally translated into another target locale. - Parameters: - `locale`: string - The locale code (e.g., 'en', 'fr', 'es'). - `targetLocale`?: string - (Optional) The locale in which the name should be returned. If not provided, it defaults to the current locale. - Returns: string - The localized name of the locale. getLocalizedUrl hook: - Purpose: Constructs a URL path that includes the specified locale, ensuring proper internationalized routing. - Parameters: - `path`: string - The base URL path (e.g., '/about', '/contact?param=value'). - `locale`: string - The target locale to include in the URL. - Returns: string - The localized URL path (e.g., '/fr/about'). getHTMLTextDir hook: - Purpose: Determines the appropriate HTML text direction ('ltr' for left-to-right or 'rtl' for right-to-left) for a given locale. - Parameters: - `locale`: string - The locale code. - Returns: 'ltr' | 'rtl' - The text direction for the specified locale. ``` -------------------------------- ### Accessing Localized Content in Next.js Server Page Source: https://intlayer.org/doc/environment/nextjs/14 Demonstrates how to use the `useIntlayer` hook within a Next.js server component page to retrieve localized content. It also illustrates the setup of `IntlayerServerProvider` and `IntlayerClientProvider` to ensure proper context propagation across server and client components. ```TypeScript import { ClientComponentExample } from "@components/ClientComponentExample"; import { ServerComponentExample } from "@components/ServerComponentExample"; import { type Next14PageIntlayer, IntlayerClientProvider } from "next-intlayer"; import { IntlayerServerProvider, useIntlayer } from "next-intlayer/server"; const Page: Next14PageIntlayer = ({ params: { locale } }) => { const content = useIntlayer("page", locale); return ( <>

{content.getStarted.main} {content.getStarted.pageLink}

); }; export default Page; ``` -------------------------------- ### Integrate Intlayer with Next.js Configuration Source: https://intlayer.org/doc/environment/nextjs/14 This JavaScript configuration file (`next.config.mjs`) integrates the `withIntlayer()` plugin from `next-intlayer/server` with your Next.js setup. This plugin ensures the building and monitoring of content declaration files, defines Intlayer environment variables, provides performance-optimizing aliases, and ensures compatibility with server components. ```javascript import { withIntlayer } from "next-intlayer/server"; /** @type {import('next').NextConfig} */ const nextConfig = {}; export default withIntlayer(nextConfig); ``` -------------------------------- ### Configure Intlayer MCP Remote Server in Cursor Source: https://intlayer.org/doc/mcp-server This JSON configuration snippet sets up the Intlayer Model Context Protocol (MCP) server in Cursor using the remote Server-Sent Events (SSE) transport method. It connects to the official Intlayer hosted service at `https://mcp.intlayer.org`. ```json { "mcpServers": { "intlayer": { "url": "https://mcp.intlayer.org", "transport": "sse" } } } ``` -------------------------------- ### Start Intlayer Editor Source: https://intlayer.org/doc/concept/editor This command initiates the Intlayer visual editor. It's crucial to run your main application in parallel, ensuring its URL matches the `applicationURL` configured for the editor to enable proper content interaction. ```bash npx intlayer-editor start ``` -------------------------------- ### Configure Intlayer MCP Remote Server in VS Code Source: https://intlayer.org/doc/mcp-server This JSON configuration snippet sets up the Intlayer Model Context Protocol (MCP) server in VS Code using the remote Server-Sent Events (SSE) transport method. It connects to the official Intlayer hosted service at `https://mcp.intlayer.org`. ```json { "servers": { "intlayer": { "url": "https://mcp.intlayer.org", "type": "sse" } } } ``` -------------------------------- ### Intlayer Component Directory Structure Example Source: https://intlayer.org/doc/get-started Illustrates the typical file organization for an Intlayer component, showing how content definition files (`index.content.cjs`) and component logic (`index.mjs`) are structured within a component directory. ```bash .└── Components └── MyComponent ├── index.content.cjs └── index.mjs ``` -------------------------------- ### Clone and Install Intlayer Extension Development Environment Source: https://intlayer.org/doc/vs-code-extension These shell commands provide the necessary steps to set up the development environment for the Intlayer VS Code extension. It involves cloning the GitHub repository and installing project dependencies using npm, preparing the project for local development and contributions. ```sh git clone https://github.com/aymericzip/intlayer-vs-code-extension.git cd intlayer-vs-code-extension npm install ``` -------------------------------- ### Start Intlayer Editor with Environment Configuration Source: https://intlayer.org/doc/concept/editor These commands allow you to start the Intlayer editor using specific environment configurations. You can either provide a direct environment file path or specify an environment name, which is useful for managing different settings across development and production environments. ```bash npx intlayer-editor start -f .env.development ``` ```bash npx intlayer-editor start -e development ``` -------------------------------- ### Example Intlayer Configuration File Source: https://intlayer.org/doc/concept/configuration This snippet demonstrates a typical `intlayer.config.ts` file, showcasing how to define internationalization locales, content directories, middleware behavior, editor settings, AI API keys, and build options for an Intlayer project. ```TypeScript import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [Locales.ENGLISH], }, content: { contentDir: ["src", "../ui-library"], }, middleware: { noPrefix: false, }, editor: { applicationURL: "https://example.com", }, ai: { apiKey: process.env.OPENAI_API_KEY, applicationContext: "This is a test application", }, build: { activateDynamicImport: true, }, }; export default config; ``` -------------------------------- ### Declare Intlayer Content in src/app.content.tsx Source: https://intlayer.org/doc/environment/vite-and-solid This TypeScript file defines a basic content declaration structure for Intlayer. It uses the `Dictionary` type from `intlayer` to ensure type safety for your localized content. This is where you will store your application's translatable strings and other content. ```typescript import { t, type Dictionary } from "intlayer"; const appContent = { key: "app", content: {}, } satisfies Dictionary; export default appContent; ``` -------------------------------- ### Intlayer CLI: Package.json Script Examples Source: https://intlayer.org/doc/concept/cli This JSON snippet demonstrates how to integrate various Intlayer CLI commands into a `package.json` file's 'scripts' section. This allows for easy execution of common Intlayer operations like building, watching for changes, pushing/pulling data, filling content, and managing documentation directly via npm or yarn scripts. ```json { "scripts": { "intlayer:build": "npx intlayer build", "intlayer:watch": "npx intlayer build --watch", "intlayer:push": "npx intlayer push", "intlayer:pull": "npx intlayer pull", "intlayer:fill": "npx intlayer fill", "intlayer:doc:translate": "npx intlayer doc translate", "intlayer:doc:review": "npx intlayer doc review" } } ``` -------------------------------- ### Integrate Intlayer Vite Plugin into vite.config.ts Source: https://intlayer.org/doc/environment/vite-and-solid This TypeScript snippet demonstrates how to add the `vite-intlayer` plugin to your Vite configuration. The `intlayerPlugin()` integrates Intlayer with the Vite bundler, enabling content declaration building and monitoring in development mode, and optimizing performance. ```typescript import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { intlayerPlugin } from "vite-intlayer"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), intlayerPlugin()], }); ``` -------------------------------- ### Intlayer Component Content Structure Example Source: https://intlayer.org/doc/concept/how-works-intlayer This snippet illustrates the recommended directory structure for Intlayer components, demonstrating how content declaration files (e.g., `index.content.cjs`) are co-located with their corresponding component files (e.g., `index.mjs`). This co-location facilitates per-component content management. ```bash .└── Components └── MyComponent ├── index.content.cjs └── index.mjs ``` -------------------------------- ### Configure Git to Ignore Intlayer Generated Files Source: https://intlayer.org/doc/environment/vite-and-solid This configuration adds a rule to the `.gitignore` file, instructing Git to ignore files and directories generated by Intlayer. This prevents unnecessary files from being committed to your version control repository, keeping your project clean. ```plaintext # Ignore the files generated by Intlayer.intlayer ``` -------------------------------- ### Configure Intlayer Locales in intlayer.config.ts Source: https://intlayer.org/doc/environment/vite-and-solid This TypeScript configuration file defines the internationalization settings for an Intlayer project. It specifies the supported locales (e.g., English, French, Spanish) and sets the default locale for the application. This file is crucial for managing language-specific content. ```typescript import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // Your other locales ], defaultLocale: Locales.ENGLISH, },};export default config; ``` -------------------------------- ### Install Intlayer CLI Globally Source: https://intlayer.org/doc/concept/cli This command installs the Intlayer Command Line Interface globally on your system, making it accessible from any directory. It is a prerequisite for using Intlayer's transpilation features. If the main 'intlayer' package is already installed, the CLI might be included, making this step optional. ```bash npm install intlayer-cli -g ``` -------------------------------- ### Integrating LocaleRouter in React App Source: https://intlayer.org/doc/environment/vite-and-react This snippet demonstrates how to wrap the main application content with the `LocaleRouter` component. This setup provides the necessary context for locale-aware routing and ensures that all child components can access the internationalization features provided by `react-intlayer`. ```tsx import { LocaleRouter } from "./components/LocaleRouter"; import type { FC } from "react"; // ... Your AppContent component const App: FC = () => ( ); ``` -------------------------------- ### Declare Localized Content with Intlayer Dictionary Source: https://intlayer.org/doc/environment/vite-and-react This TypeScript file demonstrates how to declare internationalized content using Intlayer's `t` function and `Dictionary` type. It shows examples of simple string translations and more complex ReactNode content, organized within a content declaration file. ```typescript import { t, type Dictionary } from "intlayer"; import type { ReactNode } from "react"; const appContent = { key: "app", content: { viteLogo: t({ en: "Vite logo", fr: "Logo Vite", es: "Logo Vite", }), reactLogo: t({ en: "React logo", fr: "Logo React", es: "Logo React", }), title: "Vite + React", count: t({ en: "count is ", fr: "le compte est ", es: "el recuento es ", }), edit: t({ en: ( <> Edit src/App.tsx and save to test HMR ), fr: ( <> Éditez src/App.tsx et enregistrez pour tester HMR ), es: ( <> Edita src/App.tsx y guarda para probar HMR ), }), readTheDocs: t({ en: "Click on the Vite and React logos to learn more", fr: "Cliquez sur les logos Vite et React pour en savoir plus", es: "Haga clic en los logotipos de Vite y React para obtener más información", }), }, } satisfies Dictionary; export default appContent; ``` -------------------------------- ### Using Localized Content in String Attributes (e.g., alt, src) Source: https://intlayer.org/doc/environment/nextjs/14 Provides an example of how to correctly access localized content values when assigning them to string attributes like `src` or `alt` in JSX. It highlights the necessity of calling the `.value` property of the content object to retrieve the actual string. ```JSX {content.image.value} ``` -------------------------------- ### Dynamically Change App Locale with useLocale Hook in React Source: https://intlayer.org/doc/environment/lynx-and-react This example illustrates how to implement a locale switcher using the `useLocale` hook from `react-intlayer`. It demonstrates fetching available locales, displaying the current locale, and updating the application's locale, which triggers a re-render with new translations. ```tsx import { type FC } from "react";import { getLocaleName } from "intlayer";import { useLocale } from "react-intlayer";export const LocaleSwitcher: FC = () => { const { setLocale, availableLocales, locale } = useLocale(); return ( {availableLocales.map((localeEl) => ( setLocale(localeEl)} > {getLocaleName(localeEl)} ))} );}; ``` -------------------------------- ### Configure Intlayer MCP Local Server in Claude Desktop Source: https://intlayer.org/doc/mcp-server This JSON configuration snippet sets up the Intlayer Model Context Protocol (MCP) server in Claude Desktop using the local stdio transport method. It specifies `npx` as the command to launch the `@intlayer/mcp` package, ensuring the latest available version is used. ```json { "mcpServers": { "intlayer": { "command": "npx", "args": ["-y", "@intlayer/mcp"] } } } ``` -------------------------------- ### Declare Internationalized Content with intlayer Source: https://intlayer.org/doc/environment/nextjs/14 This example demonstrates how to declare translatable content using `intlayer`'s `t` function and `Dictionary` type in `src/app/[locale]/page.content.ts`. It structures content with keys and provides translations for multiple languages (English, French, Spanish), making it accessible for internationalization within the application. ```TypeScript import { t, type Dictionary } from "intlayer";const pageContent = { key: "page", content: { getStarted: { main: t({ en: "Get started by editing", fr: "Commencez par éditer", es: "Comience por editar", }), pageLink: "src/app/page.tsx", }, }, } satisfies Dictionary;export default pageContent; ``` -------------------------------- ### Intlayer CLI: Configuration Management Source: https://intlayer.org/doc/concept/cli This section details the Intlayer CLI commands for managing configuration. It includes retrieving the current configuration settings and pushing local configurations to the Intlayer CMS for use with the Visual Editor. Common arguments for environment, base directory, and verbose logging are also described. ```APIDOC Intlayer Configuration Commands: configuration get: Retrieves the current configuration for Intlayer, particularly locale settings. Useful for verifying setup. Aliases: config get, conf get Arguments: --env: Specify the environment (e.g., development, production). --env-file: Provide a custom environment file to load variables from. --base-dir: Specify the base directory for the project. --verbose: Enable verbose logging for debugging. Usage Example: npx intlayer configuration get configuration push: Uploads your configuration to the Intlayer CMS and editor. Necessary to enable the use of distant dictionaries in the Intlayer Visual Editor. Aliases: config push, conf push Usage Example: npx intlayer configuration push ``` -------------------------------- ### Integrate i18n HTML Attributes Hook in React Application Source: https://intlayer.org/doc/environment/vite-and-react This TypeScript React example demonstrates how to integrate the `useI18nHTMLAttributes` custom hook into a main application component. By calling the hook within `AppContent`, the `` tag's `lang` and `dir` attributes are dynamically updated whenever the locale changes, ensuring consistent internationalization across the application. ```TypeScript import type { FC } from "react";import { IntlayerProvider, useIntlayer } from "react-intlayer";import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";import "./App.css";const AppContent: FC = () => { // Apply the hook to update the tag's lang and dir attributes based on the locale. useI18nHTMLAttributes(); // ... Rest of your component};const App: FC = () => ( );export default App; ``` -------------------------------- ### Configure Intlayer Locales Source: https://intlayer.org/doc/environment/create-react-app Creates an `intlayer.config.ts` file to define the supported locales (e.g., English, French, Spanish) and specify the default locale for the application's internationalization setup. ```typescript import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // Your other locales ], defaultLocale: Locales.ENGLISH, }, }; export default config; ``` -------------------------------- ### Install Intlayer Editor Development Dependency Source: https://intlayer.org/doc/concept/editor This command installs the `intlayer-editor` package as a development dependency in your project. This makes the visual editor available for use during the development phase, allowing you to manage content effectively. ```bash npm install intlayer-editor --save-dev ``` -------------------------------- ### Configure Intlayer MCP Local Server in VS Code Source: https://intlayer.org/doc/mcp-server This JSON configuration snippet sets up the Intlayer Model Context Protocol (MCP) server in VS Code using the local stdio transport method. It specifies `npx` as the command to launch the `@intlayer/mcp` package, ensuring the latest available version is used. ```json { "servers": { "intlayer": { "type": "stdio", "command": "npx", "args": ["-y", "@intlayer/mcp"] } } } ``` -------------------------------- ### Intlayer Vite Plugins API Reference Source: https://intlayer.org/doc/packages/vite-intlayer Detailed descriptions of the `intlayerPlugin()` and `intLayerMiddlewarePlugin()` functions, outlining their purpose, functionality, and how they contribute to internationalization and server-side routing in Vite applications. ```APIDOC intlayerPlugin(): - Purpose: Integrates Intlayer with Vite, ensuring the building and monitoring of content declaration files in development mode. - Functionality: Defines Intlayer environment variables within the Vite application and provides aliases to optimize performance. intLayerMiddlewarePlugin(): - Purpose: Adds server-side routing capabilities to your application. - Functionality: Automatically detects the current locale based on the URL and sets the appropriate locale cookie. If no locale is specified, it determines the most appropriate locale based on the user's browser language preferences. If no locale is detected, it redirects to the default locale. ``` -------------------------------- ### Install Intlayer VS Code Extension via CLI Source: https://intlayer.org/doc/vs-code-extension This command demonstrates how to install the Intlayer VS Code extension directly from the command line using the VS Code's built-in extension installer. It provides an alternative to installing via the Extensions Marketplace. ```sh code --install-extension intlayer ``` -------------------------------- ### Integrate LocaleRouter in React Application Source: https://intlayer.org/doc/environment/create-react-app Demonstrates how to wrap the main application content with `LocaleRouter` from `react-intlayer` to enable locale-aware routing and provide the necessary context for internationalization throughout the application. ```typescript import { LocaleRouter } from "./components/LocaleRouter"; import type { FC } from "react"; // ... Your AppContent component const App: FC = () => ( ); ``` -------------------------------- ### Intlayer Component File Structure Example Source: https://intlayer.org/doc/concept/interest This snippet illustrates the recommended directory structure for an Intlayer component, showing how content declaration files (`index.content.ts`) and component logic files (`index.tsx`) are co-located within a dedicated component folder. ```bash .└── Components └── MyComponent ├── index.content.ts └── index.tsx ``` -------------------------------- ### Get Locale Name Usage in TypeScript Source: https://intlayer.org/doc/packages/intlayer/getLocaleName This TypeScript code demonstrates how to use the `getLocaleName` function from the `intlayer` library. It shows various scenarios for retrieving the name of a locale, optionally translated into a target display locale. The examples cover single-argument calls to get the locale's own name and two-argument calls for cross-locale translation, including handling of unknown locales. ```typescript import { Locales, getLocaleName } from "intlayer"; getLocaleName(Locales.ENGLISH); // Output: "English" getLocaleName(Locales.ENGLISH, Locales.FRENCH); // Output: "Anglais" getLocaleName(Locales.ENGLISH, Locales.ESPANOL); // Output: "Inglés" getLocaleName(Locales.ENGLISH, Locales.ENGLISH); // Output: "English" getLocaleName(Locales.FRENCH); // Output: "Français" getLocaleName(Locales.FRENCH, Locales.FRENCH); // Output: "Français" getLocaleName(Locales.FRENCH, Locales.ESPANOL); // Output: "Francés" getLocaleName(Locales.FRENCH, Locales.ENGLISH); // Output: "French" getLocaleName(Locales.CHINESE); // Output: "中文" getLocaleName(Locales.CHINESE, Locales.FRENCH); // Output: "Chinois" getLocaleName(Locales.CHINESE, Locales.ESPANOL); // Output: "Chino" getLocaleName(Locales.CHINESE, Locales.ENGLISH); // Output: "Chinese" getLocaleName("unknown-locale"); // Output: "Unknown locale" ``` -------------------------------- ### Install next-intlayer Package Source: https://intlayer.org/doc/packages/next-intlayer This snippet provides the command to install the `next-intlayer` package using npm, which is the first step to integrate Intlayer into a project. ```bash npm install next-intlayer ``` -------------------------------- ### Example next-intl Client Component Message JSON Source: https://intlayer.org/doc/packages/intlayer This JSON snippet provides an example of a `next-intl` message file for a client component, demonstrating basic key-value pairs for translated content and pluralization rules for different number forms (zero, one, two, other). ```json { "myTranslatedContent": "Hello World", "zero_numberOfCar": "No cars", "one_numberOfCar": "One car", "two_numberOfCar": "Two cars", "other_numberOfCar": "Some cars" } ``` -------------------------------- ### Install preact-iso Library Source: https://intlayer.org/doc/environment/vite-and-preact Command to install the 'preact-iso' library using npm. This library is a prerequisite for implementing the localized routing solution described, providing essential routing functionalities for Preact applications. ```bash npm install preact-iso ``` -------------------------------- ### Husky Pre-Push Hook for Monorepo Intlayer Builds Source: https://intlayer.org/doc/concept/ci-cd This shell script demonstrates a Husky pre-push hook for monorepos. It uses `intlayer build` and `intlayer fill` commands with the `--base-dir` argument to process multiple applications (`app1`, `app2`) independently, ensuring their respective dictionaries are updated. ```shell # App 1 npx intlayer build --base-dir ./app1 npx intlayer fill --base-dir ./app1 --unpushed --mode fill # App 2 npx intlayer build --base-dir ./app2 npx intlayer fill --base-dir ./app2 --unpushed --mode fill ``` -------------------------------- ### Configure Intlayer Locales in intlayer.config.ts Source: https://intlayer.org/doc/environment/vite-and-react This TypeScript configuration file defines the internationalization settings for an Intlayer project. It specifies the supported locales and the default locale for the application, enabling multi-language support. ```typescript import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // Your other locales ], defaultLocale: Locales.ENGLISH, }, }; export default config; ``` -------------------------------- ### Managing Locale Context with `IntlayerProvider` in React Source: https://intlayer.org/doc/packages/react-intlayer/t This example shows how to wrap a React application with `IntlayerProvider` to manage and pass the current locale down to components. This setup is essential for the `t` function to correctly identify the active locale and return the appropriate translations. ```typescript import type { FC } from "react"; import type { Locales } from "intlayer"; import { IntlayerProvider } from "react-intlayer"; const App: FC<{ locale: Locales }> = ({ locale }) => ( {/* Your components here */} ); ```