Different returning logic when using <Trans/> or t() function added by withTranslation hoc
See original GitHub issueIs 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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.@WebKieth any update on this?