diff --git a/ts/node/locale.ts b/ts/node/locale.ts index 8737eed3b..d716f0b5c 100644 --- a/ts/node/locale.ts +++ b/ts/node/locale.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import _ from 'lodash'; import path from 'path'; +import type { LocalizerDictionary } from '../types/Localizer'; import { getAppRootPath } from './getRootPath'; function normalizeLocaleName(locale: string) { @@ -14,20 +15,18 @@ function normalizeLocaleName(locale: string) { return locale; } -function getLocaleMessages(locale: string): LocaleMessagesType { +function getLocaleMessages(locale: string): LocalizerDictionary { const onDiskLocale = locale.replace('-', '_'); const targetFile = path.join(getAppRootPath(), '_locales', onDiskLocale, 'messages.json'); return JSON.parse(fs.readFileSync(targetFile, 'utf-8')); } -export type LocaleMessagesType = Record; -export type LocaleMessagesWithNameType = { messages: LocaleMessagesType; name: string }; -export function load({ - appLocale, - logger, -}: { appLocale?: string; logger?: any } = {}): LocaleMessagesWithNameType { +export function load({ appLocale, logger }: { appLocale?: string; logger?: any } = {}): { + name: string; + messages: LocalizerDictionary; +} { if (!appLocale) { throw new TypeError('`appLocale` is required'); } diff --git a/ts/types/LocalizerKeys.ts b/ts/types/LocalizerKeys.ts deleted file mode 100644 index 3b31283ed..000000000 --- a/ts/types/LocalizerKeys.ts +++ /dev/null @@ -1,581 +0,0 @@ -export type LocalizerKeys = - | 'ByUsingThisService...' - | 'about' - | 'accept' - | 'activeMembers' - | 'add' - | 'addACaption' - | 'addAsModerator' - | 'addModerator' - | 'addModerators' - | 'addingContacts' - | 'allUsersAreRandomly...' - | 'anonymous' - | 'answeredACall' - | 'appMenuHide' - | 'appMenuHideOthers' - | 'appMenuQuit' - | 'appMenuUnhide' - | 'appearanceSettingsTitle' - | 'areYouSureClearDevice' - | 'areYouSureDeleteDeviceOnly' - | 'areYouSureDeleteEntireAccount' - | 'audio' - | 'audioMessageAutoplayDescription' - | 'audioMessageAutoplayTitle' - | 'audioNotificationsSettingsTitle' - | 'audioPermissionNeeded' - | 'audioPermissionNeededTitle' - | 'autoUpdateDownloadButtonLabel' - | 'autoUpdateDownloadInstructions' - | 'autoUpdateDownloadedMessage' - | 'autoUpdateLaterButtonLabel' - | 'autoUpdateNewVersionInstructions' - | 'autoUpdateNewVersionMessage' - | 'autoUpdateNewVersionTitle' - | 'autoUpdateRestartButtonLabel' - | 'autoUpdateSettingDescription' - | 'autoUpdateSettingTitle' - | 'banUser' - | 'banUserAndDeleteAll' - | 'beginYourSession' - | 'blindedMsgReqsSettingDesc' - | 'blindedMsgReqsSettingTitle' - | 'block' - | 'blocked' - | 'blockedSettingsTitle' - | 'callMediaPermissionsDescription' - | 'callMediaPermissionsDialogContent' - | 'callMediaPermissionsDialogTitle' - | 'callMediaPermissionsTitle' - | 'callMissed' - | 'callMissedCausePermission' - | 'callMissedNotApproved' - | 'callMissedTitle' - | 'cameraPermissionNeeded' - | 'cameraPermissionNeededTitle' - | 'cancel' - | 'cannotMixImageAndNonImageAttachments' - | 'cannotRemoveCreatorFromGroup' - | 'cannotRemoveCreatorFromGroupDesc' - | 'cannotUpdate' - | 'cannotUpdateDetail' - | 'changeAccountPasswordDescription' - | 'changeAccountPasswordTitle' - | 'changeNickname' - | 'changeNicknameMessage' - | 'changePassword' - | 'changePasswordInvalid' - | 'changePasswordTitle' - | 'changePasswordToastDescription' - | 'chooseAnAction' - | 'classicDarkThemeTitle' - | 'classicLightThemeTitle' - | 'clear' - | 'clearAll' - | 'clearAllConfirmationBody' - | 'clearAllConfirmationTitle' - | 'clearAllData' - | 'clearAllReactions' - | 'clearDataSettingsTitle' - | 'clearDevice' - | 'clearNickname' - | 'clickToTrustContact' - | 'close' - | 'closedGroupInviteFailMessage' - | 'closedGroupInviteFailMessagePlural' - | 'closedGroupInviteFailTitle' - | 'closedGroupInviteFailTitlePlural' - | 'closedGroupInviteOkText' - | 'closedGroupInviteSuccessMessage' - | 'closedGroupInviteSuccessTitle' - | 'closedGroupInviteSuccessTitlePlural' - | 'closedGroupMaxSize' - | 'confirm' - | 'confirmNewPassword' - | 'confirmPassword' - | 'connectToServerFail' - | 'connectToServerSuccess' - | 'connectingToServer' - | 'contactAvatarAlt' - | 'contactsHeader' - | 'contextMenuNoSuggestions' - | 'continue' - | 'continueYourSession' - | 'conversationsHeader' - | 'conversationsSettingsTitle' - | 'copiedToClipboard' - | 'copyErrorAndQuit' - | 'copyMessage' - | 'copyOpenGroupURL' - | 'copySessionID' - | 'couldntFindServerMatching' - | 'create' - | 'createAccount' - | 'createClosedGroupNamePrompt' - | 'createClosedGroupPlaceholder' - | 'createConversationNewContact' - | 'createConversationNewGroup' - | 'createGroup' - | 'createPassword' - | 'createSessionID' - | 'databaseError' - | 'debugLog' - | 'debugLogExplanation' - | 'decline' - | 'declineRequestMessage' - | 'delete' - | 'deleteAccountFromLogin' - | 'deleteAccountWarning' - | 'deleteContactConfirmation' - | 'deleteConversation' - | 'deleteConversationConfirmation' - | 'deleteConversationFailed' - | 'deleteConversationFailedPleaseTryAgain' - | 'deleteForEveryone' - | 'deleteJustForMe' - | 'deleteMessageQuestion' - | 'deleteMessages' - | 'deleteMessagesConfirmation' - | 'deleteMessagesQuestion' - | 'deleted' - | 'destination' - | 'device' - | 'deviceOnly' - | 'dialogClearAllDataDeletionFailedDesc' - | 'dialogClearAllDataDeletionFailedMultiple' - | 'dialogClearAllDataDeletionFailedTitle' - | 'dialogClearAllDataDeletionFailedTitleQuestion' - | 'dialogClearAllDataDeletionQuestion' - | 'disabledDisappearingMessages' - | 'disappearingMessages' - | 'disappearingMessagesDisabled' - | 'disappearingMessagesModeAfterRead' - | 'disappearingMessagesModeAfterReadSubtitle' - | 'disappearingMessagesModeAfterSend' - | 'disappearingMessagesModeAfterSendSubtitle' - | 'disappearingMessagesModeLabel' - | 'disappearingMessagesModeLegacy' - | 'disappearingMessagesModeLegacySubtitle' - | 'disappearingMessagesModeOff' - | 'disappearingMessagesModeOutdated' - | 'disappears' - | 'displayName' - | 'displayNameEmpty' - | 'displayNameTooLong' - | 'document' - | 'documents' - | 'documentsEmptyState' - | 'done' - | 'downloadAttachment' - | 'duration' - | 'editGroup' - | 'editGroupName' - | 'editMenuCopy' - | 'editMenuCut' - | 'editMenuDeleteContact' - | 'editMenuDeleteGroup' - | 'editMenuPaste' - | 'editMenuRedo' - | 'editMenuSelectAll' - | 'editMenuUndo' - | 'editProfileModalTitle' - | 'emptyGroupNameError' - | 'enable' - | 'endCall' - | 'enterAnOpenGroupURL' - | 'enterDisplayName' - | 'enterKeySettingDescription' - | 'enterKeySettingTitle' - | 'enterNewLineDescription' - | 'enterNewPassword' - | 'enterPassword' - | 'enterRecoveryPhrase' - | 'enterSendNewMessageDescription' - | 'enterSessionID' - | 'enterSessionIDOfRecipient' - | 'enterSessionIDOrONSName' - | 'entireAccount' - | 'error' - | 'establishingConnection' - | 'expandedReactionsText' - | 'expirationDuration' - | 'expirationType' - | 'failed' - | 'failedResolveOns' - | 'failedToAddAsModerator' - | 'failedToRemoveFromModerator' - | 'failedToSendMessage' - | 'faq' - | 'fileId' - | 'fileSize' - | 'fileSizeWarning' - | 'fileType' - | 'followSetting' - | 'followSettingDisabled' - | 'followSettingTimeAndType' - | 'from' - | 'getStarted' - | 'goToReleaseNotes' - | 'goToSupportPage' - | 'groupMembers' - | 'groupNamePlaceholder' - | 'helpSettingsTitle' - | 'helpUsTranslateSession' - | 'hide' - | 'hideBanner' - | 'hideConversation' - | 'hideMenuBarDescription' - | 'hideMenuBarTitle' - | 'hideNoteToSelfConfirmation' - | 'hideRequestBanner' - | 'hideRequestBannerDescription' - | 'iAmSure' - | 'image' - | 'imageAttachmentAlt' - | 'imageCaptionIconAlt' - | 'incomingCallFrom' - | 'incomingError' - | 'invalidGroupNameTooLong' - | 'invalidGroupNameTooShort' - | 'invalidNumberError' - | 'invalidOldPassword' - | 'invalidOpenGroupUrl' - | 'invalidPassword' - | 'invalidPubkeyFormat' - | 'invalidSessionId' - | 'inviteContacts' - | 'join' - | 'joinACommunity' - | 'joinOpenGroup' - | 'joinOpenGroupAfterInvitationConfirmationDesc' - | 'joinOpenGroupAfterInvitationConfirmationTitle' - | 'joinedTheGroup' - | 'keepDisabled' - | 'kickedFromTheGroup' - | 'learnMore' - | 'leave' - | 'leaveAndRemoveForEveryone' - | 'leaveCommunity' - | 'leaveCommunityFailed' - | 'leaveCommunityFailedPleaseTryAgain' - | 'leaveGroup' - | 'leaveGroupConfirmation' - | 'leaveGroupConfirmationAdmin' - | 'leaveGroupConfirmationOnlyAdmin' - | 'leaveGroupConfirmationOnlyAdminWarning' - | 'leaveGroupConrirmationOnlyAdminLegacy' - | 'leaveGroupFailed' - | 'leaveGroupFailedPleaseTryAgain' - | 'leaving' - | 'leftTheGroup' - | 'lightboxImageAlt' - | 'linkDevice' - | 'linkPreviewDescription' - | 'linkPreviewsConfirmMessage' - | 'linkPreviewsTitle' - | 'linkVisitWarningMessage' - | 'linkVisitWarningTitle' - | 'loading' - | 'mainMenuEdit' - | 'mainMenuFile' - | 'mainMenuHelp' - | 'mainMenuView' - | 'mainMenuWindow' - | 'markAllAsRead' - | 'markUnread' - | 'matchThemeSystemSettingDescription' - | 'matchThemeSystemSettingTitle' - | 'maxPasswordAttempts' - | 'maximumAttachments' - | 'media' - | 'mediaEmptyState' - | 'mediaMessage' - | 'mediaPermissionsDescription' - | 'mediaPermissionsTitle' - | 'members' - | 'message' - | 'messageBody' - | 'messageBodyMissing' - | 'messageDeletedPlaceholder' - | 'messageDeletionForbidden' - | 'messageHash' - | 'messageInfo' - | 'messageRequestAccepted' - | 'messageRequestAcceptedOurs' - | 'messageRequestAcceptedOursNoName' - | 'messageRequestPending' - | 'messageRequests' - | 'messageWillDisappear' - | 'messagesHeader' - | 'moreInformation' - | 'multipleJoinedTheGroup' - | 'multipleKickedFromTheGroup' - | 'multipleLeftTheGroup' - | 'mustBeApproved' - | 'nameAndMessage' - | 'nameOnly' - | 'newMessage' - | 'newMessages' - | 'next' - | 'nicknamePlaceholder' - | 'noAudioInputFound' - | 'noAudioOutputFound' - | 'noBlockedContacts' - | 'noCameraFound' - | 'noContactsForGroup' - | 'noContactsToAdd' - | 'noGivenPassword' - | 'noMediaUntilApproved' - | 'noMembersInThisGroup' - | 'noMessageRequestsPending' - | 'noMessagesInBlindedDisabledMsgRequests' - | 'noMessagesInEverythingElse' - | 'noMessagesInNoteToSelf' - | 'noMessagesInReadOnly' - | 'noModeratorsToRemove' - | 'noNameOrMessage' - | 'noSearchResults' - | 'notApplicable' - | 'noteToSelf' - | 'notificationForConvo' - | 'notificationForConvo_all' - | 'notificationForConvo_disabled' - | 'notificationForConvo_mentions_only' - | 'notificationFrom' - | 'notificationMostRecent' - | 'notificationMostRecentFrom' - | 'notificationPreview' - | 'notificationSettingsDialog' - | 'notificationSubtitle' - | 'notificationsSettingsContent' - | 'notificationsSettingsTitle' - | 'oceanDarkThemeTitle' - | 'oceanLightThemeTitle' - | 'offline' - | 'ok' - | 'oneNonImageAtATimeToast' - | 'onionPathIndicatorDescription' - | 'onionPathIndicatorTitle' - | 'onlyAdminCanRemoveMembers' - | 'onlyAdminCanRemoveMembersDesc' - | 'onlyGroupAdminsCanChange' - | 'open' - | 'openGroupInvitation' - | 'openGroupURL' - | 'openMessageRequestInbox' - | 'openMessageRequestInboxDescription' - | 'or' - | 'orJoinOneOfThese' - | 'originalMessageNotFound' - | 'otherPlural' - | 'otherSingular' - | 'password' - | 'passwordCharacterError' - | 'passwordLengthError' - | 'passwordTypeError' - | 'passwordViewTitle' - | 'passwordsDoNotMatch' - | 'permissionsSettingsTitle' - | 'photo' - | 'pickClosedGroupMember' - | 'pinConversation' - | 'pleaseWaitOpenAndOptimizeDb' - | 'previewThumbnail' - | 'primaryColor' - | 'primaryColorBlue' - | 'primaryColorGreen' - | 'primaryColorOrange' - | 'primaryColorPink' - | 'primaryColorPurple' - | 'primaryColorRed' - | 'primaryColorYellow' - | 'privacySettingsTitle' - | 'pruneSettingDescription' - | 'pruneSettingTitle' - | 'publicChatExists' - | 'quoteThumbnailAlt' - | 'rateLimitReactMessage' - | 'reactionListCountPlural' - | 'reactionListCountSingular' - | 'reactionNotification' - | 'reactionPopup' - | 'reactionPopupMany' - | 'reactionPopupOne' - | 'reactionPopupThree' - | 'reactionPopupTwo' - | 'read' - | 'readReceiptSettingDescription' - | 'readReceiptSettingTitle' - | 'received' - | 'recoveryPhrase' - | 'recoveryPhraseEmpty' - | 'recoveryPhraseRevealButtonText' - | 'recoveryPhraseRevealMessage' - | 'recoveryPhraseSavePromptMain' - | 'recoveryPhraseSecureTitle' - | 'remove' - | 'removeAccountPasswordDescription' - | 'removeAccountPasswordTitle' - | 'removeFromModerators' - | 'removeModerators' - | 'removePassword' - | 'removePasswordInvalid' - | 'removePasswordTitle' - | 'removePasswordToastDescription' - | 'removeResidueMembers' - | 'replyToMessage' - | 'replyingToMessage' - | 'reportIssue' - | 'requestsPlaceholder' - | 'requestsSubtitle' - | 'resend' - | 'resolution' - | 'respondingToRequestWarning' - | 'restoreUsingRecoveryPhrase' - | 'ringing' - | 'save' - | 'saveLogToDesktop' - | 'saved' - | 'savedMessages' - | 'savedTheFile' - | 'searchFor...' - | 'searchForContactsOnly' - | 'searchMessagesHeader' - | 'selectMessage' - | 'sendFailed' - | 'sendMessage' - | 'sendRecoveryPhraseMessage' - | 'sendRecoveryPhraseTitle' - | 'sending' - | 'sent' - | 'serverId' - | 'sessionMessenger' - | 'set' - | 'setAccountPasswordDescription' - | 'setAccountPasswordTitle' - | 'setDisplayPicture' - | 'setPassword' - | 'setPasswordFail' - | 'setPasswordInvalid' - | 'setPasswordTitle' - | 'setPasswordToastDescription' - | 'settingAppliesToEveryone' - | 'settingAppliesToYourMessages' - | 'settingsHeader' - | 'shareBugDetails' - | 'show' - | 'showDebugLog' - | 'showRecoveryPhrase' - | 'showRecoveryPhrasePasswordRequest' - | 'showUserDetails' - | 'someOfYourDeviceUseOutdatedVersion' - | 'spellCheckDescription' - | 'spellCheckDirty' - | 'spellCheckTitle' - | 'stagedImageAttachment' - | 'stagedPreviewThumbnail' - | 'startConversation' - | 'startInTrayDescription' - | 'startInTrayTitle' - | 'startNewConversationBy...' - | 'startedACall' - | 'support' - | 'surveyTitle' - | 'themesSettingTitle' - | 'theyChangedTheTimer' - | 'theyChangedTheTimerLegacy' - | 'theyDisabledTheirDisappearingMessages' - | 'theySetTheirDisappearingMessages' - | 'thisMonth' - | 'thisWeek' - | 'timer' - | 'timerModeRead' - | 'timerModeSent' - | 'timerOption_0_seconds' - | 'timerOption_0_seconds_abbreviated' - | 'timerOption_10_seconds' - | 'timerOption_10_seconds_abbreviated' - | 'timerOption_12_hours' - | 'timerOption_12_hours_abbreviated' - | 'timerOption_1_day' - | 'timerOption_1_day_abbreviated' - | 'timerOption_1_hour' - | 'timerOption_1_hour_abbreviated' - | 'timerOption_1_minute' - | 'timerOption_1_minute_abbreviated' - | 'timerOption_1_week' - | 'timerOption_1_week_abbreviated' - | 'timerOption_2_weeks' - | 'timerOption_2_weeks_abbreviated' - | 'timerOption_30_minutes' - | 'timerOption_30_minutes_abbreviated' - | 'timerOption_30_seconds' - | 'timerOption_30_seconds_abbreviated' - | 'timerOption_5_minutes' - | 'timerOption_5_minutes_abbreviated' - | 'timerOption_5_seconds' - | 'timerOption_5_seconds_abbreviated' - | 'timerOption_6_hours' - | 'timerOption_6_hours_abbreviated' - | 'timerSetTo' - | 'titleIsNow' - | 'to' - | 'today' - | 'tookAScreenshot' - | 'trimDatabase' - | 'trimDatabaseConfirmationBody' - | 'trimDatabaseDescription' - | 'trustThisContactDialogDescription' - | 'trustThisContactDialogTitle' - | 'tryAgain' - | 'typeInOldPassword' - | 'typingAlt' - | 'typingIndicatorsSettingDescription' - | 'typingIndicatorsSettingTitle' - | 'unableToCall' - | 'unableToCallTitle' - | 'unableToLoadAttachment' - | 'unbanUser' - | 'unblock' - | 'unblockGroupToSend' - | 'unblockToSend' - | 'unblocked' - | 'unknown' - | 'unknownCountry' - | 'unknownError' - | 'unpinConversation' - | 'unreadMessages' - | 'updateGroupDialogTitle' - | 'updatedTheGroup' - | 'userAddedToModerators' - | 'userBanFailed' - | 'userBanned' - | 'userRemovedFromModerators' - | 'userUnbanFailed' - | 'userUnbanned' - | 'video' - | 'videoAttachmentAlt' - | 'viewMenuResetZoom' - | 'viewMenuToggleDevTools' - | 'viewMenuToggleFullScreen' - | 'viewMenuZoomIn' - | 'viewMenuZoomOut' - | 'voiceMessage' - | 'welcomeToYourSession' - | 'windowMenuClose' - | 'windowMenuMinimize' - | 'windowMenuZoom' - | 'yesterday' - | 'you' - | 'youChangedTheTimer' - | 'youChangedTheTimerLegacy' - | 'youDisabledDisappearingMessages' - | 'youDisabledYourDisappearingMessages' - | 'youGotKickedFromGroup' - | 'youHaveANewFriendRequest' - | 'youLeftTheGroup' - | 'youSetYourDisappearingMessages' - | 'yourSessionID' - | 'yourUniqueSessionID' - | 'zoomFactorSettingTitle'; diff --git a/ts/types/Util.ts b/ts/types/Util.ts index 76f1d6800..a12948a33 100644 --- a/ts/types/Util.ts +++ b/ts/types/Util.ts @@ -1,11 +1,9 @@ -import { LocalizerKeys } from './LocalizerKeys'; - export type RenderTextCallbackType = (options: { text: string; key: number; isGroup: boolean; }) => JSX.Element; -export type LocalizerType = (key: LocalizerKeys, values?: Array) => string; +export type LocalizerType = typeof window.i18n; export type Noop = () => void;