Skip to content

Commit

Permalink
fix(i18n): prevent error "ReferenceError: navigator is not defined"
Browse files Browse the repository at this point in the history
  • Loading branch information
arnolanglade committed Nov 3, 2023
1 parent 790e83f commit 6be36d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/tools/i18n/intl-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import React, {
ReactElement, ReactNode, useContext, useState,
ReactElement, ReactNode, useContext, useEffect, useState,
} from 'react';
import {
FormattedMessage,
Expand Down Expand Up @@ -36,7 +36,12 @@ export const getLocale = (preferredLocale: string) => {
export default function IntlProvider(
{ children, overriddenTranslations = {} }:{ children: ReactElement, overriddenTranslations?: Partial<Translations> },
) {
const [locale, setLocale] = useState<string>(getLocale(new Intl.Locale(navigator.language).language));
const [locale, setLocale] = useState<string>('en');

useEffect(() => {
setLocale(getLocale(new Intl.Locale(navigator.language).language));
}, []);

const switchLanguage = (chosenLocale: string) => setLocale(chosenLocale);

const translations : Record<string, Translations> = {
Expand Down

0 comments on commit 6be36d5

Please sign in to comment.