Skip to content

Commit

Permalink
Fix setting the backend from the language
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 20, 2023
1 parent 35db630 commit ddb1a29
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion web/src/context/l10n.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ function reload(newLanguage) {
function L10nProvider({ children }) {
const client = useInstallerClient();
const [language, setLanguage] = useState(undefined);
const [backendPending, setBackendPending] = useState(false);
const { cancellablePromise } = useCancellablePromise();

const storeBackendLanguage = useCallback(async languageString => {
if (!client) return false;
if (!client) {
setBackendPending(true);
return false;
}

const currentLang = await cancellablePromise(client.language.getUILanguage());
const normalizedLang = languageFromBackend(currentLang);
Expand Down Expand Up @@ -247,6 +251,13 @@ function L10nProvider({ children }) {
if (!language) changeLanguage();
}, [changeLanguage, language]);

useEffect(() => {
if (!client || !backendPending) return;

storeBackendLanguage(language);
setBackendPending(false);
}, [client, language, backendPending, storeBackendLanguage]);

return (
<L10nContext.Provider value={{ language, changeLanguage }}>{children}</L10nContext.Provider>
);
Expand Down

0 comments on commit ddb1a29

Please sign in to comment.