SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Function useTranslator

    • The React binding for call-site (t()) strings — subscribes to the active language and returns a t bound to it.

      Use this instead of importing t from @sheetxl/utils inside a component. The module-level t reads a singleton, so React cannot know its value changed on a language switch: a component calling it had to separately remember to subscribe (a bare useLanguage()), and forgetting was invisible — the string simply froze at whatever language was active when the component mounted. (That is not hypothetical: the Name Box tooltip shipped exactly that way.) Taking t from this hook makes the subscription inseparable from the use — the same reason react-i18next hands you t from useTranslation() rather than exporting it.

      The returned function's identity changes when the language changes, so it is the natural memo dependency for anything that bakes a translated string:

      const t = useTranslator();
      const items = useMemo(() => [{ label: t('formulaBar.cancel') }], [t]);

      The module-level t remains exported for non-React contexts (and is what this delegates to).

      Returns TranslateFn