InvokeAI/invokeai/frontend/web/src/common/hooks/useUpdateTranslations.ts
2023-03-03 00:02:15 -05:00

18 lines
403 B
TypeScript

import React from 'react';
import { useTranslation } from 'react-i18next';
export default function useUpdateTranslations(fn: () => void) {
const { i18n } = useTranslation();
const currentLang = localStorage.getItem('i18nextLng');
React.useEffect(() => {
fn();
}, [fn]);
React.useEffect(() => {
i18n.on('languageChanged', () => {
fn();
});
}, [fn, i18n, currentLang]);
}