How do I translate strings outside of the component?
See original GitHub issueThank you for the library. I really love it. I have just one problem. How do I translate a string outside of the React component? For example I modify a Pikaday plugin like this:
class DateInput extends React.Component {
pikadayInitialOptions = {
onDraw: (pikaday) => {
(...)
let tomorrowBtn = document.createElement('a');
tomorrowBtn.appendChild(document.createTextNode(translate('pikaday.buttons.tomorrow')));
(...)
}
}
render() {
(...)
}
}
I cannot use Translate component in such case. I need a plain function (translate
in this case). How can I achieve something like that with react-localize-redux
? Thank you.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Translation outside React Component · Issue #909 - GitHub
I tried to translate strings exported outside React Components. But any methods in docs doesn't work, and I guess its normal, ...
Read more >Translating strings outside react components using react-18next
Specifically about namespacing and nesting of translations. All of the translation key:value pairs are defined OUTSIDE of the react component.
Read more >Common i18n patterns in React — LinguiJS documentation
Using jsx macros is the most straightforward way how to translate your React components. <Trans> handles translations of messages including variables and ...
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 >How to translate your React app with react-i18next
The t() function also accepts a 2nd parameter: A javascript object with parameters that i18next uses to replace parts of the translation strings....
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
This is a good question, and has pointed out a gap in the docs as this is totally doable:
When you wrap your component with the withLocalize HOC that component gains access to all the props in LocalizeContext including the translate function, which is what you’re looking for.
Using your example:
"react-localize-redux": "^3.5.2"