Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(i18n): Use i18next‘s t-function #33601

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 5 additions & 8 deletions apps/meteor/app/lib/server/methods/addUsersToRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,11 @@ export const addUsersToRoomMethod = async (userId: string, data: { rid: string;
return;
}
void api.broadcast('notify.ephemeralMessage', userId, data.rid, {
msg: i18n.t(
'Username_is_already_in_here',
{
postProcess: 'sprintf',
sprintf: [newUser.username],
},
user?.language,
),
msg: i18n.t('Username_is_already_in_here', {
postProcess: 'sprintf',
sprintf: [newUser.username],
lng: user?.language,
}),
});
}
}),
Expand Down
8 changes: 5 additions & 3 deletions apps/meteor/app/lib/server/methods/sendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { api } from '@rocket.chat/core-services';
import type { AtLeast, IMessage, IUser } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import type { RocketchatI18nKeys } from '@rocket.chat/i18n';
import { Messages, Users } from '@rocket.chat/models';
import type { TOptions } from 'i18next';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
Expand Down Expand Up @@ -97,10 +99,10 @@ export async function executeSendMessage(uid: IUser['_id'], message: AtLeast<IMe
} catch (err: any) {
SystemLogger.error({ msg: 'Error sending message:', err });

const errorMessage = typeof err === 'string' ? err : err.error || err.message;
const errorContext = err.details ?? {};
const errorMessage: RocketchatI18nKeys = typeof err === 'string' ? err : err.error || err.message;
const errorContext: TOptions = err.details ?? {};
void api.broadcast('notify.ephemeralMessage', uid, message.rid, {
msg: i18n.t(errorMessage, errorContext, user.language),
msg: i18n.t(errorMessage, { ...errorContext, lng: user.language }),
});

if (typeof err === 'string') {
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/app/lib/server/startup/mentionUserNotInChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getBlocks = (mentions: IMessage['mentions'], messageId: string, lng: strin
actionId: 'add-users',
text: {
type: 'plain_text',
text: i18n.t('Add_them', undefined, lng),
text: i18n.t('Add_them', { lng }),
},
},
dismissBlock: {
Expand All @@ -35,7 +35,7 @@ const getBlocks = (mentions: IMessage['mentions'], messageId: string, lng: strin
actionId: 'dismiss',
text: {
type: 'plain_text',
text: i18n.t('Do_nothing', undefined, lng),
text: i18n.t('Do_nothing', { lng }),
},
},
dmBlock: {
Expand All @@ -46,7 +46,7 @@ const getBlocks = (mentions: IMessage['mentions'], messageId: string, lng: strin
actionId: 'share-message',
text: {
type: 'plain_text',
text: i18n.t('Let_them_know', undefined, lng),
text: i18n.t('Let_them_know', { lng }),
},
},
} as const;
Expand Down Expand Up @@ -121,7 +121,7 @@ callbacks.add(
type: 'section',
text: {
type: 'mrkdwn',
text: i18n.t(messageLabel, { mentions: mentionsText }, language),
text: i18n.t(messageLabel, { mentions: mentionsText, lng: language }),
},
} as const,
Boolean(elements.length) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Modal } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import { useTranslation } from 'react-i18next';

type PlaceChatOnHoldModalProps = {
onOnHoldChat: () => void;
Expand All @@ -9,7 +9,7 @@ type PlaceChatOnHoldModalProps = {
};

const PlaceChatOnHoldModal = ({ onCancel, onOnHoldChat, confirm = onOnHoldChat, ...props }: PlaceChatOnHoldModalProps) => {
const t = useTranslation();
const { t } = useTranslation();

return (
<Modal {...props} data-qa-id='on-hold-modal'>
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ export const dispatchInquiryQueued = async (inquiry: ILivechatInquiryRecord, age
hasMentionToHere: false,
message: { _id: '', u: v, msg: '' },
// we should use server's language for this type of messages instead of user's
notificationMessage: i18n.t('User_started_a_new_conversation', { username: notificationUserName }, language),
room: Object.assign(room, { name: i18n.t('New_chat_in_queue', {}, language) }),
notificationMessage: i18n.t('User_started_a_new_conversation', { username: notificationUserName, lng: language }),
room: Object.assign(room, { name: i18n.t('New_chat_in_queue', { lng: language }) }),
mentionIds: [],
});
}
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ export class QueueManager {
hasMentionToHere: false,
message: { _id: '', u: v, msg: '' },
// we should use server's language for this type of messages instead of user's
notificationMessage: i18n.t('User_started_a_new_conversation', { username: notificationUserName }, language),
room: { ...room, name: i18n.t('New_chat_in_queue', {}, language) },
notificationMessage: i18n.t('User_started_a_new_conversation', { username: notificationUserName, lng: language }),
room: { ...room, name: i18n.t('New_chat_in_queue', { lng: language }) },
mentionIds: [],
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Field, FieldGroup, TextInput, FieldLabel, FieldRow, Box } from '@rocket.chat/fuselage';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { useEffect } from 'react';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

import GenericModal from '../../../../client/components/GenericModal';

Expand All @@ -13,7 +13,7 @@ type AddLinkComposerActionModalProps = {
};

const AddLinkComposerActionModal = ({ selectedText, onClose, onConfirm }: AddLinkComposerActionModalProps) => {
const t = useTranslation();
const { t } = useTranslation();
const textField = useUniqueId();
const urlField = useUniqueId();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { NavBarItem } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import { useVoipOutboundStates } from '../../contexts/CallContext';
import { useDialModal } from '../../hooks/useDialModal';

type NavBarItemOmniChannelCallDialPadProps = ComponentPropsWithoutRef<typeof NavBarItem>;

const NavBarItemOmniChannelCallDialPad = (props: NavBarItemOmniChannelCallDialPadProps) => {
const t = useTranslation();
const { t } = useTranslation();

const { openDialModal } = useDialModal();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NavBarItem } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

type NavBarItemOmnichannelCallToggleErrorProps = ComponentPropsWithoutRef<typeof NavBarItem>;

const NavBarItemOmnichannelCallToggleError = (props: NavBarItemOmnichannelCallToggleErrorProps) => {
const t = useTranslation();
const { t } = useTranslation();
return <NavBarItem icon='phone' danger data-tooltip={t('Error')} disabled {...props} />;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NavBarItem } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

type NavBarItemOmnichannelCallToggleLoadingProps = ComponentPropsWithoutRef<typeof NavBarItem>;

const NavBarItemOmnichannelCallToggleLoading = (props: NavBarItemOmnichannelCallToggleLoadingProps) => {
const t = useTranslation();
const { t } = useTranslation();
return <NavBarItem icon='phone' data-tooltip={t('Loading')} aria-label={t('VoIP_Toggle')} disabled {...props} />;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NavBarItem } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentPropsWithoutRef } from 'react';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

import { useCallerInfo, useCallRegisterClient, useCallUnregisterClient, useVoipNetworkStatus } from '../../contexts/CallContext';

type NavBarItemOmnichannelCallToggleReadyProps = ComponentPropsWithoutRef<typeof NavBarItem>;

const NavBarItemOmnichannelCallToggleReady = (props: NavBarItemOmnichannelCallToggleReadyProps) => {
const t = useTranslation();
const { t } = useTranslation();

const caller = useCallerInfo();
const unregister = useCallUnregisterClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { IUser } from '@rocket.chat/core-typings';
import { GenericMenu, useHandleMenuAction } from '@rocket.chat/ui-client';
import type { GenericMenuItemProps } from '@rocket.chat/ui-client';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React, { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import UserMenuButton from './UserMenuButton';
import { useUserMenu } from './hooks/useUserMenu';

type UserMenuProps = { user: IUser } & Omit<ComponentProps<typeof GenericMenu>, 'sections' | 'items' | 'title'>;

const UserMenu = function UserMenu({ user, ...props }: UserMenuProps) {
const t = useTranslation();
const { t } = useTranslation();
const [isOpen, setIsOpen] = useState(false);

const sections = useUserMenu(user);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/apps/gameCenter/GameCenterContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Avatar } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import {
ContextualbarTitle,
Expand All @@ -19,7 +19,7 @@ interface IGameCenterContainerProps {
}

const GameCenterContainer = ({ handleClose, handleBack, game }: IGameCenterContainerProps): ReactElement => {
const t = useTranslation();
const { t } = useTranslation();

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IUser } from '@rocket.chat/core-typings';
import { Box } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';

import GenericModal from '../../components/GenericModal';
import UserAutoCompleteMultipleFederated from '../../components/UserAutoCompleteMultiple/UserAutoCompleteMultipleFederated';
Expand All @@ -19,7 +19,7 @@ interface IGameCenterInvitePlayersModalProps {
}

const GameCenterInvitePlayersModal = ({ game, onClose }: IGameCenterInvitePlayersModalProps): ReactElement => {
const t = useTranslation();
const { t } = useTranslation();
const [users, setUsers] = useState<Array<Username>>([]);
const { name } = game;

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/components/ActionManagerBusyState.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { css } from '@rocket.chat/css-in-js';
import { Box } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useUiKitActionManager } from '../uikit/hooks/useUiKitActionManager';

const ActionManagerBusyState = () => {
const t = useTranslation();
const { t } = useTranslation();
const actionManager = useUiKitActionManager();
const [busy, setBusy] = useState(false);

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/components/AutoCompleteDepartment.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PaginatedSelectFiltered } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps, ReactElement } from 'react';
import React, { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useRecordList } from '../hooks/lists/useRecordList';
import { AsyncStatePhase } from '../hooks/useAsyncState';
Expand All @@ -28,7 +28,7 @@ const AutoCompleteDepartment = ({
showArchived = false,
...props
}: AutoCompleteDepartmentProps): ReactElement | null => {
const t = useTranslation();
const { t } = useTranslation();
const [departmentsFilter, setDepartmentsFilter] = useState<string>('');

const debouncedDepartmentsFilter = useDebouncedValue(departmentsFilter, 500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CheckOption, PaginatedMultiSelectFiltered } from '@rocket.chat/fuselage';
import type { PaginatedMultiSelectOption } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps } from 'react';
import React, { memo, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { useRecordList } from '../hooks/lists/useRecordList';
import { AsyncStatePhase } from '../hooks/useAsyncState';
Expand All @@ -24,7 +24,7 @@ const AutoCompleteDepartmentMultiple = ({
enabled = false,
onChange = () => undefined,
}: AutoCompleteDepartmentMultipleProps) => {
const t = useTranslation();
const { t } = useTranslation();
const [departmentsFilter, setDepartmentsFilter] = useState('');

const debouncedDepartmentsFilter = useDebouncedValue(departmentsFilter, 500);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/components/ConfirmOwnerChangeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import GenericModal from './GenericModal';
import RawText from './RawText';
Expand All @@ -20,7 +20,7 @@ const ConfirmOwnerChangeModal = ({
onConfirm,
onCancel,
}: ConfirmOwnerChangeModalProps) => {
const t = useTranslation();
const { t } = useTranslation();

let changeOwnerRooms = '';
if (shouldChangeOwner.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement, ComponentProps } from 'react';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

import ContextualbarAction from './ContextualbarAction';

type ContextualbarBackProps = Partial<ComponentProps<typeof ContextualbarAction>>;

const ContextualbarBack = (props: ContextualbarBackProps): ReactElement => {
const t = useTranslation();
const { t } = useTranslation();
return <ContextualbarAction {...props} title={t('Back')} name='arrow-back' />;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ComponentProps, ReactElement } from 'react';
import React, { memo } from 'react';
import { useTranslation } from 'react-i18next';

import ContextualbarAction from './ContextualbarAction';

type ContextualbarCloseProps = Partial<ComponentProps<typeof ContextualbarAction>>;

const ContextualbarClose = (props: ContextualbarCloseProps): ReactElement => {
const t = useTranslation();
const { t } = useTranslation();
return <ContextualbarAction data-qa='ContextualbarActionClose' {...props} aria-label={t('Close')} name='cross' />;
};

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/components/FilterByText.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box, Icon, TextInput, Margins } from '@rocket.chat/fuselage';
import { useAutoFocus, useMergedRefs } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ChangeEvent, FormEvent, HTMLAttributes } from 'react';
import React, { forwardRef, memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';

type FilterByTextProps = {
onChange: (filter: string) => void;
Expand All @@ -13,7 +13,7 @@ const FilterByText = forwardRef<HTMLInputElement, FilterByTextProps>(function Fi
{ placeholder, onChange: setFilter, shouldAutoFocus = false, children, ...props },
ref,
) {
const t = useTranslation();
const { t } = useTranslation();
const [text, setText] = useState('');
const autoFocusRef = useAutoFocus(shouldAutoFocus);
const mergedRefs = useMergedRefs(ref, autoFocusRef);
Expand Down
Loading
Loading