stream-chat-react-native-core
Version:
The official React Native and Expo components for Stream Chat, a service for building chat applications
25 lines (17 loc) • 683 B
text/typescript
import type { LocalMessage, MessageResponse, TranslationLanguages } from 'stream-chat';
import { useTranslationContext } from '../contexts/translationContext/TranslationContext';
type TranslationKey = `${TranslationLanguages}_text`;
export const useTranslatedMessage = (message?: LocalMessage | MessageResponse) => {
const { userLanguage } = useTranslationContext();
const translationKey: TranslationKey = `${userLanguage}_text`;
if (!message) {
return undefined;
}
if (message.i18n && translationKey in message.i18n && message.type !== 'deleted') {
return {
...message,
text: message.i18n[translationKey],
};
}
return { ...message };
};