React i18next get language in utility function


I'm using react-i18next in a React app.

As in the Quick Start guide, I can easily get the current language in a function component, with the useTranslation hook:

import { useTranslation } from 'react-i18next';


const { t, i18n } = useTranslation();
const language = i18n.language;

But how to get it in a utility function, where I can't use the hook?


You can get it by importing i18next:

import i18next from 'i18next';

export function getMessage(): string {
  const language = i18next.language;
Author: Dan Dumitru
Last Edit: March 12, 2023
Last Edit March 12, 2023
Created March 12, 2023

Pay it forward!

Did this solution help you?
You can pay it forward and write a solution here yourself, when you have one, helping future Googlers like you... >> read more

Your Comment

Feel free to post additional info or improvement suggestions.
Optional, never shown, displays gravatar.

Formatting Tips

This editor uses Markdown to easily add code in your posts.

Triple backticks for full line(s) of code (or indent 4 spaces)

let foo = 'bar';

[link text](

*italic* **bold**

More Tips