From 7e35c7fb4292d2e3cb21b0735091131c5537e78b Mon Sep 17 00:00:00 2001 From: Timofei Iatsenko Date: Wed, 7 Aug 2024 15:28:23 +0200 Subject: [PATCH 1/6] docs: update for v5 --- website/docs/guides/typescript.md | 22 --- website/docs/ref/macro.mdx | 19 +-- website/docs/ref/react.md | 2 +- website/docs/releases/migration-5.md | 185 ++++++++++++----------- website/docs/tutorials/javascript.md | 8 +- website/docs/tutorials/react-native.md | 4 +- website/docs/tutorials/react-patterns.md | 2 +- website/docs/tutorials/react-rsc.md | 9 +- website/docs/tutorials/react.md | 6 +- website/docs/tutorials/setup-react.mdx | 19 +-- website/docs/tutorials/setup-vite.md | 12 +- 11 files changed, 130 insertions(+), 158 deletions(-) delete mode 100644 website/docs/guides/typescript.md diff --git a/website/docs/guides/typescript.md b/website/docs/guides/typescript.md deleted file mode 100644 index 1bdbcdf3e..000000000 --- a/website/docs/guides/typescript.md +++ /dev/null @@ -1,22 +0,0 @@ -# Typescript - -Lingui is written in Typescript and ships with TS typings out of the box. You should not need to do anything to get type support working. - -## Macros types in non-React environments - -We investigated how macros can be used on Typescript environments where React isn't required. - -Now we're shipping two declaration types: - -- `index.d.ts` files with `@lingui/core`, `@lingui/react` and `react` as peerDependencies. -- `global.d.ts` files with just `@lingui/core` as peerDependencies. - -Now you can modify your `tsconfig.json` in your root directory and reference the global file: - -```json title="tsconfig.json" -{ - "compilerOptions": { - "types": ["./node_modules/@lingui/macro/global"] - } -} -``` diff --git a/website/docs/ref/macro.mdx b/website/docs/ref/macro.mdx index 9eb16ec3b..6fb64faec 100644 --- a/website/docs/ref/macro.mdx +++ b/website/docs/ref/macro.mdx @@ -14,24 +14,25 @@ import TabItem from "@theme/TabItem"; - Babel macros require [babel-plugin-macros](https://github.com/kentcdodds/babel-plugin-macros) to work. If you use a framework (for example GatsbyJS, Create React App > 2.0) you might already have macros enabled. Otherwise, install it as any other Babel plugin: - - Install `babel-plugin-macros` as a dev dependency and `@lingui/macro` as dependency: + Lingui macros require `@lingui/babel-plugin-lingui-macro` or [babel-plugin-macros](https://github.com/kentcdodds/babel-plugin-macros) to work. + + Recommended way is to use `@lingui/babel-plugin-lingui-macro` directly, but if you use a framework which is not allowing to change babel configuration (for example GatsbyJS, Create React App > 2.0) that frameworks might support `babel-plugin-macros` out of the box. + + - Install `@lingui/babel-plugin-lingui-macro` as a dev dependency: ```bash npm2yarn npm install --save-dev babel-plugin-macros - npm install --save @lingui/macro ``` - - Add `macros` to the top of plugins section in your Babel config: + - Add `@lingui/babel-plugin-lingui-macro` to the top of plugins section in your Babel config: ```json { - "plugins": ["macros"] + "plugins": ["@lingui/babel-plugin-lingui-macro"] } ``` When using any preset, first check if it includes the `macros` plugin. These presets already includes the `macros` plugin: `react-scripts`. - - Install `@lingui/swc-plugin` as a dev dependency and `@lingui/macro` as dependency: @@ -46,10 +47,6 @@ import TabItem from "@theme/TabItem"; -:::note -It's recommended to install `@lingui/macro` package as a production dependency rather than development one to avoid `import/no-extraneous-dependencies` errors in ESLint. -::: - :::tip Don't miss the [Lingui ESLint Plugin](/docs/ref/eslint-plugin.md) which can help you find and prevent common l10n mistakes in your code. ::: @@ -1026,7 +1023,7 @@ Use `` inside `` macro if you want to provide `id`, `context` or ### `useLingui` :::note -`useLingui` is available from lingui v5 +`useLingui` React macro is available from lingui v5 ::: Gives access to a [`t`](/docs/ref/macro.mdx#t) macro bound to the local i18n object passed from React context. diff --git a/website/docs/releases/migration-5.md b/website/docs/releases/migration-5.md index 8fe852d02..6ccf9d833 100644 --- a/website/docs/releases/migration-5.md +++ b/website/docs/releases/migration-5.md @@ -4,9 +4,9 @@ TBD -## React and Js Macros was split to separate packages +## React and JS Macros were split to separate packages -The current Lingui macro is tightly coupled with React, which poses problems for developers using Lingui with vanilla JavaScript or other frameworks such as Vue. +The previous Lingui macro was tightly coupled with React, which posed problems for developers using Lingui with vanilla JavaScript or other frameworks such as Vue. The macro package has been split into two separate entrypoints from existing packages: @@ -30,7 +30,7 @@ function MyComponent() { This is not a breaking change. -Imports from `@lingui/macro` still work, but marked as deprecated. They would be removed in the next major release. +Imports from `@lingui/macro` still work, but are marked as deprecated. They will be removed in the next major release. You can use an automatic [codemod](https://www.npmjs.com/package/@lingui/codemods) to convert your codebase to the new imports: @@ -38,7 +38,7 @@ You can use an automatic [codemod](https://www.npmjs.com/package/@lingui/codemod npx @lingui/codemods split-macro-imports ``` -After this codemod you can drop `@lingui/macro` from your dependencies. +After running this codemod you can drop `@lingui/macro` from your dependencies. ## Full Vue.js support @@ -61,23 +61,23 @@ Whitespace cleaning in JSX expression is unavoidable, otherwise formatting your // without new lines in start and end of tag ``` -Previously Lingui used some regexp based approach to normalize whitespaces in the JSX nodes processed by macro. That approach was not perfect and didn't follow JSX language grammar, that sometimes lead to unexpected results. +Previously, Lingui used a regexp based approach to normalize whitespaces in the JSX nodes processed by macro. That approach was not perfect and didn't follow JSX language grammar, which sometimes lead to unexpected results. -With this version lingui use the same set of rules to clean whitespaces as it's done in JSX. This lead to more anticipated results without unwanted cleaning of whitespaces. +With v5, Lingui uses the same set of rules to clean whitespaces as it's done in JSX. This leads to more predictable results without unwanted cleaning of whitespaces. ### No whitespaces cleaning in `t` and other JS macros -We've got a feedback which we agreed on that whitespaces cleaning in the JS macros is redundant and counterintuitive. +Based on feedback from developers, it was agreed that whitespace cleaning in the JS macros is redundant and counterintuitive. ```js t`Label:◦` + value; ``` -Note the space after ":", it's expected by developer to be there, but "normalization" will remove it. +Note the space after ":" - it's expected by developer to stay in the extracted string, but "normalization" would previously remove it. -Other example would be a markdown, or just a whatever purpose developer want to have an original formatting. +Other example would be markdown, or any reason for which developer wants to keep the original formatting. -Starting from v5 cleaning whitespaces for JS macros is completely removed. +Starting from v5, cleaning whitespaces for JS macros is completely removed. ### Migration @@ -87,7 +87,7 @@ There is no way to automatically convert your catalogs to pick-up existing trans If you use TMS (such as Crowdin or Translation.io), migration should be pretty simple. Use Translation Memory feature (or analog). -if you don't use TMS you will need to migrate catalogs manually. +If you don't use a TMS you will need to migrate catalogs manually. ## Standalone `babel-plugin-lingui-macro` @@ -107,7 +107,7 @@ You will benefit from a slightly faster transpiling time and more configuration The `useLingui` macro simplify working with non-jsx messages in react components. -Before this macro you have to combine `t` or `msg` macro with an instance returned from `useLingui` hook: +Before this macro you had to combine `t` or `msg` macro with the i18n instance returned from `useLingui` hook: ```jsx import { t, msg } from "@lingui/macro"; @@ -142,7 +142,7 @@ TBD ([#1958](https://github.com/lingui/js-lingui/pull/1958)) ## Print placeholder values for better translation context -If the message contains unnamed placeholders, such as `{0}` Lingui will print theirs values into PO comments, so translators and AI got more context what this placeholder is about. +If the message contains unnamed placeholders such as `{0}`, Lingui will print their values into PO comments, so that translators and AI get more context on what the placeholder is about. ```js t`Hello ${user.name} ${value}`; diff --git a/website/docs/tutorials/javascript.md b/website/docs/tutorials/javascript.md index dfc74d9b8..90f6bae1c 100644 --- a/website/docs/tutorials/javascript.md +++ b/website/docs/tutorials/javascript.md @@ -25,7 +25,7 @@ Let's start with the three major packages: > Transforms messages wrapped in tagged template literals to ICU MessageFormat and validates them. -1. Install `@lingui/cli`, `@lingui/babel-plugin-lingui-macro` and Babel core packages as a development dependencies and `@lingui/core` as a runtime dependency: +1. Install `@lingui/cli`, `@lingui/babel-plugin-lingui-macro` and Babel core packages as development dependencies and `@lingui/core` as a runtime dependency: ```bash npm2yarn npm install --save-dev @lingui/cli @lingui/babel-plugin-lingui-macro @babel/core diff --git a/website/docs/tutorials/react-patterns.md b/website/docs/tutorials/react-patterns.md index e932de358..2e7e7687c 100644 --- a/website/docs/tutorials/react-patterns.md +++ b/website/docs/tutorials/react-patterns.md @@ -102,7 +102,7 @@ function MyComponent() { } ``` -Note that we import `useLingui` from `@lingui/react/macro`. There is also a runtime version of `useLingui` hook exported from `@lingui/react`. In the case above, it doesn't matter what version to choose since we use only `i18n` object which is presented in both. +Note that we import `useLingui` from `@lingui/react/macro`. There is also a runtime version of `useLingui` hook exported from `@lingui/react`. In the case above, it doesn't matter what version to choose since we use only `i18n` object which is returned by both. ::: diff --git a/website/docs/tutorials/setup-react.mdx b/website/docs/tutorials/setup-react.mdx index 97ccc140e..a92eee34f 100644 --- a/website/docs/tutorials/setup-react.mdx +++ b/website/docs/tutorials/setup-react.mdx @@ -29,7 +29,7 @@ import TabItem from "@theme/TabItem"; "plugins": ["@lingui/babel-plugin-lingui-macro"] } ``` - When using any preset, first check if it includes the `macros` plugin. Than you don't need to install and setup `@lingui/babel-plugin-lingui-macro`. These presets already includes the `macros` plugin: `react-scripts`. + When using any preset, first check if it includes the `macros` plugin. If so, then you don't need to install and set up `@lingui/babel-plugin-lingui-macro`. For example, the `react-scripts` preset is known to contain the `macros` plugin. From eb154d92ec10195cb3371082cd11bd155b7b95e5 Mon Sep 17 00:00:00 2001 From: Timofei Iatsenko Date: Wed, 14 Aug 2024 09:30:12 +0200 Subject: [PATCH 5/6] prettier --- website/docs/tutorials/setup-react.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/tutorials/setup-react.mdx b/website/docs/tutorials/setup-react.mdx index a92eee34f..4f04a158f 100644 --- a/website/docs/tutorials/setup-react.mdx +++ b/website/docs/tutorials/setup-react.mdx @@ -29,7 +29,7 @@ import TabItem from "@theme/TabItem"; "plugins": ["@lingui/babel-plugin-lingui-macro"] } ``` - When using any preset, first check if it includes the `macros` plugin. If so, then you don't need to install and set up `@lingui/babel-plugin-lingui-macro`. For example, the `react-scripts` preset is known to contain the `macros` plugin. + When using any preset, first check if it includes the `macros` plugin. If so, then you don't need to install and set up `@lingui/babel-plugin-lingui-macro`. For example, the `react-scripts` preset is known to contain the `macros` plugin. From e7b95a87496ba26db85cbae3b135650737f40fd0 Mon Sep 17 00:00:00 2001 From: Timofei Iatsenko Date: Wed, 14 Aug 2024 09:35:08 +0200 Subject: [PATCH 6/6] doc fix --- website/docs/tutorials/setup-vite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/tutorials/setup-vite.md b/website/docs/tutorials/setup-vite.md index b3449ef2e..b7ad0906a 100644 --- a/website/docs/tutorials/setup-vite.md +++ b/website/docs/tutorials/setup-vite.md @@ -12,7 +12,7 @@ The Lingui Vite integration: ## Setup with [@vitejs/plugin-react](https://www.npmjs.com/package/@vitejs/plugin-react) {#setup-with-vitejs-plugin-react} -`@vitejs/plugin-react` uses Babel to transform your code. LinguiJS relies on `babel-plugin-macros` to compile JSX to [ICU Message Format](/docs/guides/message-format.md) and for automatic ID generation. +`@vitejs/plugin-react` uses Babel to transform your code. LinguiJS relies on `@lingui/babel-plugin-lingui-macro` to compile JSX to [ICU Message Format](/docs/guides/message-format.md) and for automatic ID generation. 1. Install `@lingui/cli`, `@lingui/vite-plugin`, `@lingui/babel-plugin-lingui-macro` as development dependencies and `@lingui/react` as a runtime dependency: