Skip to content

Commit

Permalink
Replace useTranslation in some modules
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Oct 23, 2024
1 parent fc3a55f commit 8286938
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/client/hooks/useDownloadFromServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Emitter } from '@rocket.chat/emitter';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import type { TFunction } from 'i18next';
import { useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';

Expand All @@ -17,7 +18,7 @@ if ('serviceWorker' in navigator) {
});
}

export const registerDownloadForUid = (uid: string, t: ReturnType<typeof useTranslation>['t'], title?: string) => {
export const registerDownloadForUid = (uid: string, t: TFunction, title?: string) => {
ee.once(uid, ({ result }) => {
downloadAs({ data: [new Blob([result])] }, title ?? t('Download'));
});
Expand Down
9 changes: 5 additions & 4 deletions apps/meteor/client/views/admin/import/ImportProgressPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { ProgressStep } from '@rocket.chat/core-typings';
import { Box, Margins, ProgressBar, Throbber } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useEndpoint, useTranslation, useStream, useRouter } from '@rocket.chat/ui-contexts';
import { useToastMessageDispatch, useEndpoint, useStream, useRouter } from '@rocket.chat/ui-contexts';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { ImportingStartedStates } from '../../../../app/importer/lib/ImporterProgressStep';
import { numberFormat } from '../../../../lib/utils/stringUtils';
Expand All @@ -14,7 +15,7 @@ import { useErrorHandler } from './useErrorHandler';
const ImportProgressPage = function ImportProgressPage() {
const queryClient = useQueryClient();
const streamer = useStream('importers');
const t = useTranslation();
const { t, i18n } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const handleError = useErrorHandler();

Expand Down Expand Up @@ -77,7 +78,7 @@ const ImportProgressPage = function ImportProgressPage() {

switch (step) {
case 'importer_done':
t.has(message) &&
i18n.exists(message) &&
dispatchToastMessage({
type: 'success',
message: t(message),
Expand All @@ -87,7 +88,7 @@ const ImportProgressPage = function ImportProgressPage() {

case 'importer_import_failed':
case 'importer_import_cancelled':
t.has(message) && handleError(message);
i18n.exists(message) && handleError(message);
router.navigate('/admin/import');
return;

Expand Down
11 changes: 6 additions & 5 deletions apps/meteor/client/views/banners/hooks/useUserBanners.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useTranslation, useUser } from '@rocket.chat/ui-contexts';
import { useUser } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import * as banners from '../../../lib/banners';
import { useDismissUserBannerMutation } from './useDismissUserBannerMutation';

export const useUserBanners = () => {
const user = useUser();

const t = useTranslation();
const { t, i18n } = useTranslation();
const { mutate: dismissUserBanner } = useDismissUserBannerMutation();

useEffect(() => {
Expand All @@ -25,8 +26,8 @@ export const useUserBanners = () => {

banners.open({
id: firstBanner.id,
title: t.has(firstBanner.title) ? t(firstBanner.title) : firstBanner.title,
text: t.has(firstBanner.text) ? t(firstBanner.text, firstBanner.textArguments) : firstBanner.text,
title: i18n.exists(firstBanner.title) ? t(firstBanner.title) : firstBanner.title,
text: i18n.exists(firstBanner.text) ? t(firstBanner.text, firstBanner.textArguments) : firstBanner.text,
modifiers: firstBanner.modifiers,
action() {
if (firstBanner.link) {
Expand All @@ -37,5 +38,5 @@ export const useUserBanners = () => {
dismissUserBanner({ id: firstBanner.id });
},
});
}, [dismissUserBanner, t, user?.banners]);
}, [dismissUserBanner, i18n, t, user?.banners]);
};
18 changes: 12 additions & 6 deletions apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import type { IRoom } from '@rocket.chat/core-typings';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { useLocalStorage } from '@rocket.chat/fuselage-hooks';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { useMethod, useSetting, useTranslation, useUserPreference } from '@rocket.chat/ui-contexts';
import { useMethod, useSetting, useUserPreference } from '@rocket.chat/ui-contexts';
import React, { useMemo } from 'react';
import type { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';

import { hasAtLeastOnePermission } from '../../../../app/authorization/client';
import { CannedResponse } from '../../../../app/canned-responses/client/collections/CannedResponse';
Expand All @@ -24,15 +25,20 @@ import type { ComposerBoxPopupUserProps } from '../composer/ComposerBoxPopupUser
import type { ComposerPopupContextValue } from '../contexts/ComposerPopupContext';
import { ComposerPopupContext, createMessageBoxPopupConfig } from '../contexts/ComposerPopupContext';

const ComposerPopupProvider = ({ children, room }: { children: ReactNode; room: IRoom }) => {
type ComposerPopupProviderProps = {
children: ReactNode;
room: IRoom;
};

const ComposerPopupProvider = ({ children, room }: ComposerPopupProviderProps) => {
const { _id: rid, encrypted: isRoomEncrypted } = room;
const userSpotlight = useMethod('spotlight');
const suggestionsCount = useSetting<number>('Number_of_users_autocomplete_suggestions');
const cannedResponseEnabled = useSetting<boolean>('Canned_Responses_Enable');
const [recentEmojis] = useLocalStorage('emoji.recent', []);
const isOmnichannel = isOmnichannelRoom(room);
const useEmoji = useUserPreference('useEmojis');
const t = useTranslation();
const { t, i18n } = useTranslation();
const e2eEnabled = useSetting<boolean>('E2E_Enable');
const unencryptedMessagesAllowed = useSetting<boolean>('E2E_Allow_Unencrypted_Messages');
const encrypted = isRoomEncrypted && e2eEnabled && !unencryptedMessagesAllowed;
Expand Down Expand Up @@ -289,8 +295,8 @@ const ComposerPopupProvider = ({ children, room }: { children: ReactNode; room:
const item = slashCommands.commands[command];
return {
_id: command,
params: item.params && t.has(item.params) ? t(item.params) : item.params ?? '',
description: item.description && t.has(item.description) ? t(item.description) : item.description,
params: item.params && i18n.exists(item.params) ? t(item.params) : item.params ?? '',
description: item.description && i18n.exists(item.description) ? t(item.description) : item.description,
permission: item.permission,
...(encrypted && { disabled: encrypted }),
};
Expand Down Expand Up @@ -365,7 +371,7 @@ const ComposerPopupProvider = ({ children, room }: { children: ReactNode; room:
},
}),
].filter(Boolean);
}, [t, cannedResponseEnabled, isOmnichannel, recentEmojis, suggestionsCount, userSpotlight, rid, call, useEmoji, encrypted]);
}, [t, i18n, cannedResponseEnabled, isOmnichannel, recentEmojis, suggestionsCount, userSpotlight, rid, call, useEmoji, encrypted]);

return <ComposerPopupContext.Provider value={value} children={children} />;
};
Expand Down

0 comments on commit 8286938

Please sign in to comment.