Skip to content

Support multiple Tolgee instances on one page #3462

@kushuh

Description

@kushuh

There is a feature in react-i18next (looks undocumented) that lets you hot swap the i18n instance using props:

import { useTranslation, Translation, Trans } from "react-i18next";
import i18nInstance from "./i18n";

function MyComponent() {
  const { t } = useTranslation("ns", { i18n: i18nInstance  });

  return (
    <>
      <Trans i18n={i18nInstance} {...} />
      <Translation i18n={i18nInstance} {...} />
    </>
  );
}

This is immensely helpful when working with internal packages, as each package can use its own i18n instance (and translation source) without conflicting with the top-level provider.

import { Component, Sync } from "my-package";
import i18n from "./i18n";

function MyApp() {
  return (
    <I18nProvider i18n={i18n}>
      {/* Sync component is used to sync the language */}
      {/* of the package with the application. */}
      <Sync i18n={i18n} />

      {/* Component uses its own i18n instance and */}
      {/* translation source. */}
      <Component />
    </I18nProvider>
  );
}

Can such feature be considered with Tolgee ?

import { useTranslate, T } from '@tolgee/react';
import tolgeeInstance from "./tolgee";


function MyComponent() {
  const { t } = useTranslate("ns", { tolgee: tolgeeInstance });

  return (
    <>
      <T tolgee={tolgeeInstance} {...} />
    </>
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions