Files
AFFiNE-Mirror/packages/frontend/i18n
renovate 75516c7584 chore: bump up i18next version to v24 (#8898)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [i18next](https://www.i18next.com) ([source](https://redirect.github.com/i18next/i18next)) | [`^23.11.1` -> `^24.0.0`](https://renovatebot.com/diffs/npm/i18next/23.16.5/24.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/i18next/24.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/i18next/24.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/i18next/23.16.5/24.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/i18next/23.16.5/24.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>i18next/i18next (i18next)</summary>

### [`v24.0.0`](https://redirect.github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#2400)

[Compare Source](https://redirect.github.com/i18next/i18next/compare/v23.16.8...v24.0.0)

**This is a major breaking release:**

-   remove support for older environments
-   remove old i18next JSON formats
    -   To convert your existing v3 translations to the v4 format, have a look at [i18next-v4-format-converter](https://redirect.github.com/i18next/i18next-v4-format-converter) or this [web tool](https://i18next.github.io/i18next-v4-format-converter-web/).
-   remove support for compatibility to v1 API
-   Intl API is mandatory now and will not fallback anymore
-   possible compatibility layer for older formats: `test/compatibility/v4/v4Compatibility.js`
-   rename `initImmediate` to `initAsync`
-   fallback to `dev` language if plural rule not found
-   remove TypeScript v4 support. TypeScript v5 is now an optional peer dependency
-   addresses
    -   [2244](https://redirect.github.com/i18next/i18next/pull/2244)
    -   [2184](https://redirect.github.com/i18next/i18next/pull/2184)
    -   [2213](https://redirect.github.com/i18next/i18next/issues/2213)
    -   [2206](https://redirect.github.com/i18next/i18next/pull/2206)
    -   [2208](https://redirect.github.com/i18next/i18next/issues/2208)
    -   [2148](https://redirect.github.com/i18next/i18next/issues/2148)
    -   [2254](https://redirect.github.com/i18next/i18next/issues/2254)

➡️ check out the [migration guide](https://www.i18next.com/misc/migration-guide#v23.x.x-to-v24.0.0)

### [`v23.16.8`](https://redirect.github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23168)

[Compare Source](https://redirect.github.com/i18next/i18next/compare/v23.16.7...v23.16.8)

-   fix(plural): Create cache entry for PluralRules created as part of the fallback flow [2256](https://redirect.github.com/i18next/i18next/pull/2256)

### [`v23.16.7`](https://redirect.github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23167)

[Compare Source](https://redirect.github.com/i18next/i18next/compare/v23.16.6...v23.16.7)

-   if plural rule is not found, try to search with language only code [2252](https://redirect.github.com/i18next/i18next/issues/2252)

### [`v23.16.6`](https://redirect.github.com/i18next/i18next/blob/HEAD/CHANGELOG.md#23166)

[Compare Source](https://redirect.github.com/i18next/i18next/compare/v23.16.5...v23.16.6)

-   fix: Small typo in the type definitions [2250](https://redirect.github.com/i18next/i18next/pull/2250)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/toeverything/AFFiNE).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xOS4wIiwidXBkYXRlZEluVmVyIjoiMzkuMTkuMCIsInRhcmdldEJyYW5jaCI6ImNhbmFyeSIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->
2024-11-26 10:51:10 +00:00
..
2024-06-20 02:19:41 +00:00

i18n

Usages

  • Update missing translations into the base resources, a.k.a the src/resources/en.json
  • Replace literal text with translation keys
import { useI18n, LOCALES } from '@affine/i18n';
// src/resources/en.json
// {
//     'Text': 'some text',
//     'Switch to language': 'Switch to {{language}}', // <- you can interpolation by curly brackets
// };

const App = () => {
  const i18n = useI18n();
  const changeLanguage = (language: string) => {
    i18n.changeLanguage(language);
  };

  return (
    <div>
      <div>{i18n['Workspace Settings']()}</div>
      <>
        {LOCALES.map(option => {
          return (
            <button
              key={option.name}
              onClick={() => {
                changeLanguage(option.tag);
              }}
            >
              {option.originalName}
            </button>
          );
        })}
      </>
    </div>
  );
};

How the i18n workflow works?

  • When the src/resources/en.json(base language) updated and merged to the develop branch, will trigger the languages-sync action.
  • The languages-sync action will check the base language and add missing translations to the Tolgee platform.
  • This way, partners from the community can update the translations.

How to sync translations manually

  • Set token as environment variable
export TOLGEE_API_KEY=tgpak_XXXXXXX
  • Run the sync-languages:check to check all languages
  • Run the sync-languages script to add new keys to the Tolgee platform
  • Run the download-resources script to download the latest full-translation translation resources from the Tolgee platform

References