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

Using <Translate> inside <options> #8104

Closed
6 tasks done
luisamor opened this issue Sep 16, 2022 · 2 comments
Closed
6 tasks done

Using <Translate> inside <options> #8104

luisamor opened this issue Sep 16, 2022 · 2 comments
Labels
closed: question This issue is a user error/misunderstanding.

Comments

@luisamor
Copy link

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Hi!

I need translate some select <options> with the component. For example:

        <p className="hero__subtitle">
          <Translate id="hero__subtitle" description="home page subtitle">
            Other subtitle
          </Translate>
        </p>

        <div className="margin-bottom--lg">
          <select>
            <option value="left">
              <Translate id="test.left">Left</Translate>
            </option>
            <option value="right">
              <Translate id="test.left">Right</Translate>
            </option>
          </select>
        </div>

This renders an [object Object] string

image

This is a fork from https://docusaurus.new --> https://github.com/luisamor/docusaurus-options-issue

And you can test it in:
https://stackblitz.com/edit/github-zuuia5-wgx6mj?file=src/pages/index.js

Reproducible demo

https://stackblitz.com/edit/github-zuuia5-wgx6mj?file=src/pages/index.js

Steps to reproduce

Simply look at the in the main page. Expected behavior I wanna see the text or the translated text, not an object. Actual behavior inside a HTML renders an Object. Your environment Public source code: https://github.com/luisamor/docusaurus-options-issue Public site URL: https://stackblitz.com/edit/github-zuuia5-wgx6mj?file=src/pages/index.js Docusaurus version used: 2.1.0 Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 105.0.5195.125 & node >=16.14 Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS Monterey 12.2.1 Self-service [X] I'd be willing to fix this bug myself.

@luisamor luisamor added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Sep 16, 2022
@Josh-Cena
Copy link
Collaborator

Hi—Translate is a JSX.Element, which is an object. If you want to use a string (which option accepts as its children), you need to use translate(). This is already mentioned in the docs: https://docusaurus.io/docs/i18n/tutorial#translate-your-react-code

Use the one that better fits the context semantically. For example, the <Translate> can be used as React children, while for props that expect a string, the callback can be used.

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2022
@Josh-Cena Josh-Cena added closed: question This issue is a user error/misunderstanding. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Sep 19, 2022
@Josh-Cena
Copy link
Collaborator

Docs updated in #8115 to make it more explicit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: question This issue is a user error/misunderstanding.
Projects
None yet
Development

No branches or pull requests

2 participants