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

Cypress cannot show the useTranslation string correctly #30363

Open
angie-wei opened this issue Oct 4, 2024 · 0 comments
Open

Cypress cannot show the useTranslation string correctly #30363

angie-wei opened this issue Oct 4, 2024 · 0 comments
Labels
stage: needs information Not enough info to reproduce the issue

Comments

@angie-wei
Copy link

angie-wei commented Oct 4, 2024

Current behavior

The code uses the react-intl package for text translation, but it displays the label name instead of the defined translation string.

image

Desired behavior

expect

Test code to reproduce

video_text.tsx

import React from 'react';
import { useTranslation as t } from '@utils/hooks';

export default function App() {
  const MORE_VIDEOS = t('label_more_videos');
  return (
    <div className='App'>
      <p data-test-id='more-video-title'>{MORE_VIDEOS}</p>
    </div>
  );
}

useTranslation.ts

import { useIntl } from 'react-intl';

const useTranslation = (
  id: string,
  values?: Record<string, string | number>
): string => {
  const { formatMessage } = useIntl();

  return formatMessage({ id }, values);
};

export default useTranslation;

Cypress Version

13.6.0

Node version

v18.18.0

Operating System

Windows 11

Debug Logs

Use Cypress will show the below error, but the regular browser will show the translation normally.

Error: [@formatjs/intl Error MISSING_TRANSLATION] Missing message: "label_more_videos" for locale "en", using id as fallback. 

    at new MissingTranslationError (error.js:76:1)
    at formatMessage (message.js:65:1)
    at formatMessage (provider.js:46:18)
    at useTranslation (useTranslation.ts:9:10)
    at VideoCarousel (VideoCarousel.tsx:45:24)
    at renderWithHooks (react-dom.development.js:16305:1)
    at updateFunctionComponent (react-dom.development.js:19588:1)
    at updateSimpleMemoComponent (react-dom.development.js:19425:1)
    at beginWork (react-dom.development.js:21678:1)
    at beginWork$1 (react-dom.development.js:27426:1)

Other

No response

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants