diff --git a/src/components/auth/AuthPhoneNumber.tsx b/src/components/auth/AuthPhoneNumber.tsx index 529cd45c5..f881f7dbd 100644 --- a/src/components/auth/AuthPhoneNumber.tsx +++ b/src/components/auth/AuthPhoneNumber.tsx @@ -70,7 +70,7 @@ const AuthPhoneNumber: FC = ({ const inputRef = useRef(null); const suggestedLanguage = getSuggestedLanguage(); - const continueText = useLangString(suggestedLanguage, 'ContinueOnThisLanguage'); + const continueText = useLangString(suggestedLanguage, 'ContinueOnThisLanguage', true); const [country, setCountry] = useState(); const [phoneNumber, setPhoneNumber] = useState(); const [isTouched, setIsTouched] = useState(false); diff --git a/src/components/auth/AuthQrCode.tsx b/src/components/auth/AuthQrCode.tsx index 981ff654e..4ef43d546 100644 --- a/src/components/auth/AuthQrCode.tsx +++ b/src/components/auth/AuthQrCode.tsx @@ -58,7 +58,7 @@ const AuthCode: FC = ({ const lang = useLang(); // eslint-disable-next-line no-null/no-null const qrCodeRef = useRef(null); - const continueText = useLangString(suggestedLanguage, 'ContinueOnThisLanguage'); + const continueText = useLangString(suggestedLanguage, 'ContinueOnThisLanguage', true); const [isLoading, markIsLoading, unmarkIsLoading] = useFlag(); const [isQrMounted, markQrMounted, unmarkQrMounted] = useFlag(); diff --git a/src/components/middle/composer/hooks/useEditing.ts b/src/components/middle/composer/hooks/useEditing.ts index 4102da0a8..dfeb4bd88 100644 --- a/src/components/middle/composer/hooks/useEditing.ts +++ b/src/components/middle/composer/hooks/useEditing.ts @@ -116,8 +116,7 @@ const useEditing = ( noWebPage: false, }); } - // eslint-disable-next-line react-hooks-static-deps/exhaustive-deps -- `as const` not yet supported by linter - }, [editedMessage, chatId, getHtml, threadId] as const); + }, [editedMessage, chatId, getHtml, threadId, getShouldResetNoWebPageDebounced]); const restoreNewDraftAfterEditing = useCallback(() => { if (!draft) return; diff --git a/src/hooks/useLangString.ts b/src/hooks/useLangString.ts index d05994f1b..b2d4d1b01 100644 --- a/src/hooks/useLangString.ts +++ b/src/hooks/useLangString.ts @@ -1,18 +1,21 @@ import * as langProvider from '../util/langProvider'; import { useState } from '../lib/teact/teact'; -const useLangString = (langCode: string | undefined, key: string): string | undefined => { +const useLangString = ( + langCode: string | undefined, + key: string, + shouldIgnoreSameValue = false, +): string | undefined => { const [translation, setTranslation] = useState(); if (langCode) { langProvider .getTranslationForLangString(langCode, key) .then((value) => { - // The string is not translated, maybe the language pack was not loaded due to network or a timeout errors - if (value === key) { + // The string is not translated, maybe the language pack was not loaded due to network errors or a timeout + if (shouldIgnoreSameValue && value === key) { return; } - setTranslation(value); }); } diff --git a/src/util/authLangPack.ts b/src/util/fallbackLangPackInitial.ts similarity index 98% rename from src/util/authLangPack.ts rename to src/util/fallbackLangPackInitial.ts index df4afda20..f705851f6 100644 --- a/src/util/authLangPack.ts +++ b/src/util/fallbackLangPackInitial.ts @@ -2,7 +2,7 @@ import type { ApiLangPack } from '../api/types'; -export const authLangPack = { +export const fallbackLangPackInitial = { WrongNumber: { key: 'WrongNumber', value: 'Wrong number?', diff --git a/src/util/langProvider.ts b/src/util/langProvider.ts index 79afeb651..a0bccc9e2 100644 --- a/src/util/langProvider.ts +++ b/src/util/langProvider.ts @@ -10,7 +10,7 @@ import * as cacheApi from './cacheApi'; import { callApi } from '../api/gramjs'; import { createCallbackManager } from './callbacks'; import { formatInteger } from './textFormat'; -import { authLangPack } from './authLangPack'; +import { fallbackLangPackInitial } from './fallbackLangPackInitial'; export interface LangFn { (key: string, value?: any, format?: 'i', pluralValue?: number): string; @@ -105,16 +105,11 @@ function createLangFn() { } } - if (!langPack && !fallbackLangPack && !authLangPack[key]) { - return key; - } - - const shouldImportFallback = !fallbackLangPack && !(langPack?.[key] || fallbackLangPack?.[key]); - if (shouldImportFallback) { + if (!fallbackLangPack) { void importFallbackLangPack(); } - const langString = (langPack?.[key]) || (fallbackLangPack?.[key]) || authLangPack[key]; + const langString = langPack?.[key] || fallbackLangPack?.[key] || fallbackLangPackInitial[key]; if (!langString) { return key; }