-
Notifications
You must be signed in to change notification settings - Fork 12
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
Simple translate strings #7
Comments
@tomasz89nowak that's a great suggestion! I like your idea for it as a render prop. I'll push an update soon that has that feature :) |
@tomasz89nowak this is now available in v2.1.0 :) |
@amsul thanks, I saw it, great job! I will use it, but please consider making HOC too or provide translating function as a render prop, because translating form with 15 inputs with translated placeholders and titles is pretty complex now :).
Proposition:
What do You think? |
@tomasz89nowak true! I hadn't thought about it in that much depth. What do you think about adding a new component (and removing the custom renderer I added): <Translator>
{({ translate }) => (
<input
placeholder={translate({ text: 'placeholder' })}
title={translate({
text: 'Hi {firstName}',
data: { firstName: 'Sergey' },
})}
/>
)}
</Translator> |
Looks very good for me, that's all I need :) <Translator>
{({ translate }) => (
<input
placeholder={translate('placeholder')}
title={translate('Hi {firstName}', {
data: { firstName: 'Sergey' }
})}
/>
)}
</Translator> |
@tomasz89nowak I just pushed it to Regarding the syntax, I agree less characters are usually nice. But for several reasons, I like having named arguments instead of ordered arguments - and the closest we can get to that in JavaScript is with this syntax of "pseudo-named" arguments. |
I tried and it works, but it's not always consistent with Translate component:
<Translate text="something" /> // returns "something"
<Translator>
{({ translate }) => (
<div>{translate({ text: "something" })}</div> // returns ""
)}
</Translator>
<Translate text="something {someData}" /> // it crashes, what is expected behavior for me
<Translator>
{({ translate }) => (
<div>{translate({ text: "something {someData}" })}</div> // returns ""
)}
</Translator> That's all I found for now. |
@tomasz89nowak debugging is visibly implemented in the If you create your provider like this: Regarding the empty string for Although, I agree it would be nice to have a way to indicate it visibly. Logging it to the console is not ideal imo.. Would love to hear some thoughts. |
Now that I think about it, one option is that Only issue there is that since you can render many children in there, it's difficult to know which one in specific has the missing translation. |
I see another issue in wrapping entire children - wrapper must be HTML tag so it will modify the DOM tree, so it can spoil styles like <Translator tag="div"> Logging to the console is not ideal, but better than wrapping children in my opinion. |
True - that's not ideal. For starters, I guess it should at least default to the string passed in to be translated. Regarding debugging it, another possible solution is to use Portals and display any missing strings in some kind of overlaid sidebar. |
Hi, Your library has almost all I need for my project and is simple and clear to use, but I can't figure out how to translate input placeholders, html element title or just string in constructor. Is it even possible? If not, do You plan to add HOC or render prop component to use it like:
or
EDIT
🙌 Possible solution
I wrote simple HOC to handle my problem, it need some improvements but works for a simple case
The text was updated successfully, but these errors were encountered: