### Run Vite Development Server Source: https://github.com/lingui/js-lingui/blob/main/examples/remix-vite-babel/README.md Starts the Vite development server for the Remix.run application. This command is used during development to preview changes and test functionality. ```shellscript npm run dev ``` -------------------------------- ### Lingui Vite Plugin Setup with SWC Source: https://github.com/lingui/js-lingui/blob/main/website/docs/installation.mdx Integrates Lingui.js with Vite using the `@vitejs/plugin-react-swc` (SWC) for faster message extraction and catalog compilation. Requires installing `@lingui/vite-plugin`, `@lingui/swc-plugin`, and `@lingui/react`. ```bash npm install --save-dev @lingui/vite-plugin @lingui/swc-plugin npm install --save @lingui/react ``` ```typescript import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { lingui } from "@lingui/vite-plugin"; export default defineConfig({ plugins: [ react({ plugins: [["@lingui/swc-plugin", {}]], }), lingui(), ], }); ``` -------------------------------- ### Run Production Application Source: https://github.com/lingui/js-lingui/blob/main/examples/remix-vite-babel/README.md Starts the production version of the Remix.run application. This command is used to run the application after it has been built for deployment. ```shell npm start ``` -------------------------------- ### Lingui Vite Plugin Setup with Babel Source: https://github.com/lingui/js-lingui/blob/main/website/docs/installation.mdx Integrates Lingui.js with Vite using the `@vitejs/plugin-react` (Babel) for message extraction and catalog compilation. Requires installing `@lingui/vite-plugin` and `@lingui/react`. ```bash npm install --save-dev @lingui/vite-plugin npm install --save @lingui/react ``` ```typescript import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { lingui } from "@lingui/vite-plugin"; export default defineConfig({ plugins: [ react({ babel: { plugins: ["@lingui/babel-plugin-lingui-macro"], }, }), lingui(), ], }); ``` -------------------------------- ### Lingui Basic Configuration (lingui.config.js) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/installation.mdx Defines the essential configuration for Lingui.js, specifying source and target locales, and the path for message catalogs. This file is crucial for Lingui to identify and manage translations within your project. ```javascript import { defineConfig } from "@lingui/cli"; export default defineConfig({ sourceLocale: "en", locales: ["cs", "en"], catalogs: [ { path: "/src/locales/{locale}/messages", include: ["src"], }, ], }); ``` -------------------------------- ### Install Lingui Babel Macro Plugin (npm2yarn) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/installation.mdx Installs the Lingui Babel macro plugin as a development dependency using npm2yarn. This is a prerequisite for using Lingui with Babel for code transformation. ```bash npm install --save-dev @lingui/babel-plugin-lingui-macro ``` -------------------------------- ### Install Lingui SWC Plugin (npm2yarn) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/installation.mdx Installs the Lingui SWC plugin as a development dependency using npm2yarn. This is required for integrating Lingui with SWC for faster code transformations. ```bash npm install --save-dev @lingui/swc-plugin ``` -------------------------------- ### Loading Multiple Catalogs with i18n.load Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-3.md Example demonstrating how to load multiple locale catalogs at once using the i18n.load method in @lingui/core, maintaining backward compatibility with the previous version's behavior. ```javascript // i18n.js import { i18n } from "@lingui/core"; import catalogEn from "./locale/en/messages.js"; import catalogFr from "./locale/fr/messages.js"; i18n.load({ en: catalogEn.messages, fr: catalogFr.messages, }); ``` -------------------------------- ### Install Lingui CLI with npm Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/cli.md Installs the Lingui CLI package as a development dependency using npm. This command is typically run once during project setup. ```bash npm install --save-dev @lingui/cli ``` -------------------------------- ### Install ESLint and Lingui ESLint Plugin Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/eslint-plugin.md Installs the necessary packages for ESLint and the Lingui ESLint plugin as development dependencies. This is a prerequisite for using the plugin. ```bash npm install --save-dev eslint npm install --save-dev eslint-plugin-lingui ``` -------------------------------- ### Start local documentation server Source: https://github.com/lingui/js-lingui/blob/main/CONTRIBUTING.md Builds the documentation, watches for changes, and starts a local development server at http://localhost:3000/. This command is used to preview documentation changes in real-time during development. ```sh yarn start ``` -------------------------------- ### Migrating from Lingui Babel Presets to Macros (npm) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-3.md Provides instructions for migrating from Lingui's Babel presets to the new macro system using npm. This involves uninstalling the old preset and installing `@lingui/macro` and `babel-plugin-macros`, followed by updating the Babel configuration. ```bash npm uninstall @lingui/babel-preset-react npm install --dev @lingui/macro babel-plugin-macros ``` -------------------------------- ### Install Lingui Core Package Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/core.md Installs the @lingui/core package using npm or yarn. This is the first step to integrate LinguiJS internationalization into your project. ```bash npm install --save @lingui/core ``` ```bash yarn add @lingui/core ``` -------------------------------- ### Install Lingui SWC Plugin (npm/yarn) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/swc-plugin.md Installs the @lingui/swc-plugin as a development dependency using npm or yarn. This is the initial step for integrating Lingui with SWC. ```bash npm install --save-dev @lingui/swc-plugin ``` ```bash yarn add --dev @lingui/swc-plugin ``` -------------------------------- ### Install website dependencies Source: https://github.com/lingui/js-lingui/blob/main/CONTRIBUTING.md Installs all necessary Node.js dependencies for the documentation website, which is built using Docusaurus. This command assumes Yarn is installed and configured. ```sh yarn install ``` -------------------------------- ### Build Production Application Source: https://github.com/lingui/js-lingui/blob/main/examples/remix-vite-babel/README.md Builds the Remix.run application for production deployment. This command generates optimized assets and server code for a production environment. ```shell npm run build ``` -------------------------------- ### Start Development Server (npm, yarn, pnpm) Source: https://github.com/lingui/js-lingui/blob/main/examples/vite-project-react-swc/README.md Commands to initiate the development server for the project. These commands are compatible with npm, Yarn, and pnpm package managers. ```bash npm run dev ``` ```bash yarn dev ``` ```bash pnpm dev ``` -------------------------------- ### Install @lingui/react Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/react.md Installs the @lingui/react package using npm or yarn. This package is essential for integrating Lingui's localization features into React applications. ```bash npm install --save @lingui/react ``` ```bash yarn add @lingui/react ``` -------------------------------- ### Simplify non-JSX messages with useLingui macro Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-5.md This example shows how to use the new `useLingui` macro to simplify handling non-JSX messages in React components. It contrasts the previous method requiring `t` or `msg` with `i18n` from `useLingui` hook, with the new, more concise macro usage. ```jsx ```jsx import { t, msg } from "@lingui/macro"; import { useLingui } from "@lingui/react"; function MyComponent() { const { i18n, _ } = useLingui(); const a = t(i18n)`Text`; // or const b = _(msg`Text`); } ``` ``` ```jsx ```jsx import { useLingui } from "@lingui/react/macro"; function MyComponent() { const { t } = useLingui(); const a = t`Text`; } ``` ``` -------------------------------- ### Install @lingui/metro-transformer Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/metro-transformer.mdx Install the package as a development dependency using npm or yarn. This command is used to add the necessary transformer to your project. ```bash npm install --save-dev @lingui/metro-transformer ``` ```bash yarn add --dev @lingui/metro-transformer ``` -------------------------------- ### Migrating I18nProvider in React Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-3.md This snippet demonstrates the migration of the I18nProvider in React applications from version 2.x to 3.x. The declarative API using catalogs is replaced by an imperative setup of the i18n instance. ```diff import { I18nProvider } from '@lingui/react' import { i18n } from "@lingui/core" + import { en } from 'make-plural/plurals' import { messages } from './locale/en/messages.js' + i18n.loadLocaleData('en', { plurals: en }) + i18n.load('en', messages) + i18n.activate('en') function App() { return ( - + ) } ``` -------------------------------- ### Whitespace Handling in JSX Macros (Prettier Example) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-5.md Demonstrates robust whitespace cleaning in Lingui's JSX macros. The example shows how Lingui preserves intended whitespace within JSX Trans components, preventing formatting tools like Prettier from altering extracted messages. ```jsx // prettier-ignore Hello◦{"◦"}◦world ``` -------------------------------- ### Install Lingui Vite Plugin (npm2yarn) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/vite-plugin.md Installs the `@lingui/vite-plugin` as a development dependency. This command is compatible with both npm and yarn package managers. ```bash npm install --save-dev @lingui/vite-plugin ``` -------------------------------- ### Install @lingui/babel-plugin-lingui-macro using npm or yarn Source: https://github.com/lingui/js-lingui/blob/main/packages/babel-plugin-lingui-macro/README.md Installs the @lingui/babel-plugin-lingui-macro as a development dependency. This is the first step to integrate LinguiJS macros into your project. ```sh npm install --save-dev @lingui/babel-plugin-lingui-macro yarn add --dev @lingui/babel-plugin-lingui-macro ``` -------------------------------- ### Install PO Formatter - npm Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/catalog-formats.md This command installs the `@lingui/format-po` package as a development dependency using npm. This package provides the PO catalog formatter for Lingui JS. ```bash npm install --save-dev @lingui/format-po ``` -------------------------------- ### Lingui ESLint Plugin Flat Config - Recommended Setup Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/eslint-plugin.md Configures the Lingui ESLint plugin using the recommended set of rules within ESLint's Flat Config format. This setup enables all built-in recommended rules for i18n best practices. ```javascript import pluginLingui from "eslint-plugin-lingui"; export default [ pluginLingui.configs["flat/recommended"], // Any other config... ]; ``` -------------------------------- ### Print placeholder values in PO comments Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-5.md This example illustrates the new feature that prints placeholder variable names in PO comments for better translation context. It shows how a message with unnamed placeholders like `{0}` is now extracted with descriptive comments. ```js ```js t`Hello ${user.name} ${value}`; ``` ``` ```po ```po #. placeholder {0}: user.name msgid "Hello {0} {value}" ``` ``` -------------------------------- ### Loading Single Catalog with i18n.load Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-3.md Illustrates the simplified usage of the i18n.load method in @lingui/core, now allowing catalogs to be loaded for a single locale at a time. ```diff import { i18n } from "@lingui/core" import catalogEn from './locale/en/messages.js' - i18n.load({ en: catalogEn }) + i18n.load('en', catalogEn.messages) ``` -------------------------------- ### Simplified lingui-extract Command Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-4.md Demonstrates the simplification of the `lingui extract` command. The `NODE_ENV=development` prefix is no longer required, making the command cleaner and easier to execute. ```bash lingui extract ``` -------------------------------- ### JavaScript: Setup Lingui i18n Singleton Source: https://github.com/lingui/js-lingui/blob/main/website/docs/tutorials/javascript.md Initializes and activates the Lingui i18n singleton by loading translation messages for a specific locale. It requires the `@lingui/core` package and pre-compiled message catalogs. ```javascript import { i18n } from "@lingui/core"; import { messages } from "path-to-locale/en/messages.js"; i18n.load("en", messages); i18n.activate("en"); ``` -------------------------------- ### Install @lingui/loader Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/loader.md Installs the @lingui/loader package as a development dependency using npm or yarn. ```bash npm install --save-dev @lingui/loader ``` ```bash yarn add --dev @lingui/loader ``` -------------------------------- ### ESLint Plugin Configuration Source: https://github.com/lingui/js-lingui/blob/main/website/blog/2024-11-28-announcing-lingui-5.0/index.md Example of configuring the Lingui ESLint plugin, showing compatibility with both flat configuration (eslint.config.js) and legacy .eslintrc formats. This helps catch common usage errors and enforce best practices. ```json { "plugins": [ "@lingui" ], "rules": { "@lingui/no-unused-captures": "error", "@lingui/no-def-whitespace": "error" } } ``` -------------------------------- ### Install PO Gettext Plurals Formatter - npm Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/catalog-formats.md This command installs the `@lingui/format-po-gettext` package as a development dependency using npm. This package is used for reading and writing PO files with gettext-native plurals, useful for localization backends that don't support ICU plural syntax. ```bash npm install --save-dev @lingui/format-po-gettext ``` -------------------------------- ### i18next Context Example (JavaScript) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/misc/i18next.md Shows how i18next handles context for differentiating translations of the same sentences by using a 'context' option. ```js import i18next from "i18next"; i18next.t("Right", { context: "direction" }); ``` -------------------------------- ### Lingui ESLint Plugin Legacy Config - Recommended Setup Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/eslint-plugin.md Applies the recommended rules for the Lingui ESLint plugin using the legacy `.eslintrc` configuration format. This extends the existing ESLint configuration with Lingui's best practices. ```json { "extends": ["plugin:lingui/recommended"] } ``` -------------------------------- ### Install @lingui/detect-locale Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/locale-detector.md Installs the @lingui/detect-locale package using npm or yarn. This package is essential for implementing locale detection strategies. ```bash npm install --save @lingui/detect-locale ``` ```bash yarn add @lingui/detect-locale ``` -------------------------------- ### Using Default i18n Instance in @lingui/core Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-3.md This code illustrates the change in @lingui/core where a default i18n instance is now exported, simplifying its usage compared to the previous setupI18n function. ```diff + import { i18n } from "@lingui/core" - import { setupI18n } from "@lingui/core" - const i18n = setupI18n() i18n.activate('en') ``` -------------------------------- ### Install development packages with Yarn Workspaces Source: https://github.com/lingui/js-lingui/blob/main/CONTRIBUTING.md Installs all development packages and dependencies for all workspaces within the js-lingui project using Yarn Workspaces. This command ensures all parts of the monorepo are set up correctly. ```sh yarn ``` -------------------------------- ### Install Vue.js Extractor using npm/yarn Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/extractor-vue.md This command installs the @lingui/extractor-vue package as a development dependency using either npm or yarn. ```bash npm install --save-dev @lingui/extractor-vue ``` ```bash yarn add --dev @lingui/extractor-vue ``` -------------------------------- ### Configure Lingui: Full Consistency Dev/Prod (TypeScript) Source: https://github.com/lingui/js-lingui/blob/main/website/docs/guides/optimizing-bundle-size.md This setup ensures full consistency between development and production by stripping all messages in both environments. This approach is useful for catching internationalization issues early. It requires setting `stripMessageField` to true in the macro config and `setMessagesCompiler` to null in the runtime setup. ```typescript // Macro config stripMessageField: true; // Runtime setup i18n.setMessagesCompiler(null); ``` -------------------------------- ### Example Usage of Split Lingui Macros Source: https://github.com/lingui/js-lingui/blob/main/website/docs/releases/migration-5.md Illustrates the usage of separated Lingui macros in a React component. It imports 'Trans' from '@lingui/react/macro' for JSX elements and 'msg' from '@lingui/core/macro' for core JavaScript string definitions. ```jsx import { Trans } from "@lingui/react/macro"; import { msg } from "@lingui/core/macro"; const colors = [msg`Red`, msg`Yellow`, msg`Green`]; function MyComponent() { Hi, my name is {name}; } ``` -------------------------------- ### Install JSON formatter for js-lingui Source: https://github.com/lingui/js-lingui/blob/main/website/docs/ref/catalog-formats.md This command installs the JSON formatter for js-lingui using npm or yarn. The JSON format is used to store messages and comes in minimal and lingui styles. ```bash npm install --save-dev @lingui/format-json ``` -------------------------------- ### React/React Native: Simplified I18nProvider and useLingui interplay Source: https://github.com/lingui/js-lingui/blob/main/website/docs/tutorials/react-native.md This example illustrates the basic setup of `I18nProvider` and the usage of `useLingui` hook with the `t` macro for translating both static headings and dynamic button titles within a React Native component. ```tsx import { I18nProvider } from "@lingui/react"; import { Trans, useLingui } from "@lingui/react/macro"; import { i18n } from "@lingui/core"; ; //... const Inbox = ({ markAsRead }) => { const { t } = useLingui(); return ( Message Inbox