2

Example:

<h1 translate="no" className="clientName">Jay</h1>

Hi Guys, the code above is in my react project and its apparent that the attribute translate is not working in React

Does anyone know an alternative solution, even through Javascript, as I do not want google to translate the names of people on my site?

Thanks!

4
  • I have the same issue. I'll specify that by "not working" I mean, that React ignores this attribute and it's not being rendered in the final html at all. Commented Jun 22, 2020 at 8:53
  • Which version of React are you using? Commented Jun 22, 2020 at 9:05
  • In my case it's last issue of React 15 Commented Jun 22, 2020 at 9:21
  • @MattLeonowicz, please check the answer, I think that might help you. Commented Jun 22, 2020 at 10:32

4 Answers 4

1

As per the doc, Not all browsers support this attribute. Verify the doc whether the browser in which you work supports that attribute.

Sign up to request clarification or add additional context in comments.

Comments

1

Please check browser support of translate="no" here, not supported by most of then

You can also test the same thing in the browser you want to test : https://j74bu.csb.app/


For specific google translate as alternate solution, you can use className="notranslate"

<h1 className="notranslate">agradável</h1>

WORKING DEMO : (Link to test)

Edit peaceful-khorana-j74bu

Comments

1
+50

While translate attribute is not supported in a few browsers, I think that issue in your case is that React isn't passing the translate attribute to the DOM element.

This could happen if you are using a version of react older than 16.0.0. Prior to 16.0.0, react would omit custom attributes from being passed to the DOM. In doing so it also did not honour some valid HTML attributes as the valid attribute list is quite huge.

From v16.0.0, react doesn't omit these attributes from being passed to the DOM and hence you would be able to properly use it.

Please check the migration guide for more details

All you need to do is to upgrade your version of react to the latest version using

  yarn upgrade --latest react react-dom

or you can simply try to upgrade to v16.0.0 with

yarn upgrade [email protected] [email protected]

Comments

0
<html translate="no">

you can basically do this at the top of your html file

3 Comments

Well, I do want it to translate other sections of the page, just not the names within the page
@CoderAz you can also try class="notranslate" maybe this one fit for you
thanks for the suggesstion but that didnt work either :s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.