Skip to content

Commit ec96736

Browse files
zubidenAjaxy
authored andcommitted
Localization: Support custom languages (#7425)
1 parent ea92be2 commit ec96736

35 files changed

Lines changed: 559 additions & 95 deletions

‎src/api/gramjs/apiBuilders/misc.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,14 @@ export function buildLangStrings(strings: GramJs.TypeLangPackString[]) {
321321

322322
export function buildApiLanguage(lang: GramJs.TypeLangPackLanguage): ApiLanguage {
323323
const {
324-
name, nativeName, langCode, pluralCode, rtl, stringsCount, translatedCount, translationsUrl, beta, official,
324+
name, nativeName, langCode, baseLangCode, pluralCode, rtl, stringsCount, translatedCount,
325+
translationsUrl, beta, official,
325326
} = lang;
326327
return {
327328
name,
328329
nativeName,
329330
langCode,
331+
baseLangCode,
330332
pluralCode,
331333
isRtl: rtl,
332334
isBeta: beta,

‎src/api/gramjs/methods/client.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ const ABORT_CONTROLLERS = new Map<string, AbortController>();
8989
let client: TelegramClient;
9090
let currentUserId: string | undefined;
9191

92+
export function setLanguageCode({ langCode }: { langCode: string }) {
93+
return client.setLanguageCode(langCode);
94+
}
95+
9296
export async function init(initialArgs: ApiInitialArgs, onConnected?: NoneToVoidFunction) {
9397
if (DEBUG) {
9498
// eslint-disable-next-line no-console

‎src/api/gramjs/methods/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export {
22
cancelWebTokenAuthorization, destroy, disconnect, downloadMedia, fetchCurrentUser, repairFileReference,
33
abortChatRequests, abortRequestGroup,
44
setForceHttpTransport, setShouldDebugExportedSenders, setAllowHttpTransport, requestChannelDifference,
5-
setOpenedChannelIds,
5+
setOpenedChannelIds, setLanguageCode,
66
} from './client';
77

88
export {

‎src/api/gramjs/methods/settings.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ export async function fetchLanguage({
502502
const result = await invokeRequest(new GramJs.langpack.GetLanguage({
503503
langPack,
504504
langCode,
505-
}));
505+
}), { shouldThrow: true });
506506
if (!result) {
507507
return undefined;
508508
}

‎src/api/types/settings.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type LangPack = {
5151

5252
export type CachedLangData = {
5353
langPack: LangPack;
54+
baseLangPack?: LangPack;
5455
language: ApiLanguage;
5556
};
5657

‎src/assets/localization/fallback.strings‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,15 @@
539539
"DataSettings" = "Data and Storage";
540540
"PrivacySettings" = "Privacy and Security";
541541
"Language" = "Language";
542+
"LanguageTitle" = "Change language?";
543+
"LanguageAlert" = "You are about to apply a language pack ({language}) that is {percent}% complete.\n\nThis will translate the entire interface. You can suggest corrections via the {link}.\n\nYou can change your language back at any time in {settings}.";
544+
"LanguageCustomAlert" = "You are about to apply a custom language pack ({language}) that is {percent}% complete.\n\nThis will translate the entire interface. You can suggest corrections via the {link}.\n\nYou can change your language back at any time in {settings}.";
545+
"LanguageUnknownCustomAlert" = "Unfortunately, this language pack ({language}) doesn't contain data for Telegram Web A. You can contribute to this language pack using the {link}.";
546+
"LanguageAlready" = "You're already using this language pack. You can change your language back at any time in {settings}.";
547+
"LanguageNotFound" = "Sorry, this language pack doesn't exist.";
548+
"LanguageLoadFailed" = "Couldn't load this language pack. Please try again.";
549+
"LanguageApply" = "Apply Language";
550+
"LanguageTranslateLink" = "translation platform";
542551
"SettingsExperimental" = "Experimental settings";
543552
"PrivacyPhone" = "Phone Number";
544553
"PrivacyLastSeen" = "Last Seen & Online";

‎src/bundles/extra.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export { default as AiToneEmojiPickerModal }
7878
from '../components/middle/composer/AiMessageEditorModal/AiToneEmojiPickerModal';
7979
export { default as AiTonePreviewModal }
8080
from '../components/modals/aiTonePreview/AiTonePreviewModal';
81+
export { default as LanguageModal } from '../components/modals/language/LanguageModal';
8182

8283
export { default as AttachmentModal } from '../components/middle/composer/AttachmentModal';
8384
export { default as MediaEditor } from '../components/ui/mediaEditor/MediaEditor';

‎src/components/auth/AuthPhoneNumber.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ const AuthPhoneNumber = ({
111111

112112
useEffect(() => {
113113
if (isConnected) {
114-
loadCountryList({ langCode: language });
114+
loadCountryList({ langCode: lang.code });
115115
}
116-
}, [isConnected, language]);
116+
}, [isConnected, lang.code]);
117117

118118
useEffect(() => {
119119
if (nearestCountry && phoneCodeList && !country && !isTouched) {

‎src/components/common/Composer.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import {
104104
selectIsPremiumPurchaseBlocked,
105105
selectIsReactionPickerOpen,
106106
selectIsRightColumnShown,
107+
selectLanguageCode,
107108
selectNewestMessageWithBotKeyboardButtons,
108109
selectNotifyDefaults,
109110
selectNotifyException,
@@ -3362,7 +3363,8 @@ export default memo(withGlobal<OwnProps>(
33623363
shouldSuggestStickers, shouldSuggestCustomEmoji, shouldUpdateStickerSetOrder, shouldPaidMessageAutoApprove,
33633364
lastRecordMessageMode,
33643365
} = global.settings.byKey;
3365-
const { language, shouldCollectDebugLogs } = selectSharedSettings(global);
3366+
const { shouldCollectDebugLogs } = selectSharedSettings(global);
3367+
const language = selectLanguageCode(global);
33663368
const {
33673369
forwardMessages: { messageIds: forwardMessageIds },
33683370
messageMediaEditorRequest,

‎src/components/common/CustomEmojiPicker.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
selectIsChatWithSelf,
2828
selectIsCurrentUserPremium,
2929
} from '../../global/selectors';
30-
import { selectSharedSettings } from '../../global/selectors/sharedState';
30+
import { selectLanguageCode } from '../../global/selectors/settings';
3131
import animateHorizontalScroll from '../../util/animateHorizontalScroll';
3232
import { IS_TOUCH_ENV } from '../../util/browser/windowEnvironment';
3333
import buildClassName from '../../util/buildClassName';
@@ -639,7 +639,7 @@ export default memo(withGlobal<OwnProps>(
639639
const isSavedMessages = Boolean(chatId && selectIsChatWithSelf(global, chatId));
640640
const chatFullInfo = chatId ? selectChatFullInfo(global, chatId) : undefined;
641641
const collectibleStatuses = global.collectibleEmojiStatuses?.statuses;
642-
const { language } = selectSharedSettings(global);
642+
const language = selectLanguageCode(global);
643643
const baseEmojiKeywords = global.emojiKeywords[BASE_EMOJI_KEYWORD_LANG];
644644
const emojiKeywords = language !== BASE_EMOJI_KEYWORD_LANG ? global.emojiKeywords[language] : undefined;
645645

0 commit comments

Comments
 (0)