question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different returning logic when using <Trans/> or t() function added by withTranslation hoc

See original GitHub issue

Is your feature request related to a problem? Please describe. I wrote a component, which includes some common fields with translation on front-end side and additional fields, which I got from backend - their labels have already translated. So, if I use <Trans/> on pretranslated fields - I set this label on key attribute. Of course this key isnt found inside translation json and tag returns empty string. But when I use t() function added by withTranslation hoc - this function returns entered key string if key didnt find.

Describe the solution you’d like I would prefer to use standalone <Trans/> component instead a hoc (Code is cleaner, performance is better), so just return an entered key string with Trans, as you do it with t()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Mar 9, 2020

Depends on what the called function does (1 function calling 1000 functions might be slower than calling 100 functions calling no other functions 😁)

If you like you might provide a PR fixing the issue -> setting transEmptyNodeValue: false should return the key as is. Else I will try to fix this later this week.

0reactions
adraicommented, Apr 13, 2020

@WebKieth any update on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

withTranslation (HOC) - react-i18next documentation
The withTranslation is a classic HOC (higher order component) and gets the t function and i18n instance inside your component via props.
Read more >
A Guide to React Localization with i18next | Phrase
We can now use i18next's t() function to localize our app's name using the translation resources we provided during setup. t() takes a...
Read more >
React localization with i18next - LogRocket Blog
To localize a React application using the i18next, we must add the ... the i18n instance provides a translation function called t() ....
Read more >
i18next React - Changing language only works after browser ...
In react, try to use the useTranslation hook or the withTranslation HOC. That will detect the language change.
Read more >
Development translation guide - TerriaJS
import React from "react"; import { withTranslation } from "react-i18next"; function MyComponent({ t, i18n }) { return <p>{t("my translated text")}</p>; } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found