-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Wrong tag guessing in Trans component #342
Comments
Thanks, now it worked. Is this the only way we know how to put the tags? Is there any documentation on the tag numbers? |
Tag numbers are basically index of react components children passed to Trans component |
What about the example on the homepage: https://react.i18next.com/
How does the json string look like? |
Hello <1><0>{{name}}</0></1>, you have <3>{{count}}</3> unread message. <5>Go to messages</5>. Simplified Trans component children: Trans.children = [
'Hello ',
{ children: [{ name: 'Jan' }] }, // index 1 -> child object index 0
', you have',
{ count: 10 }, // index 3
' unread messages. ',
{ children: [ 'Go to messages' ] }, // index 5
'.'
] |
@jamuhl I think the first bit is missing? |
? you mean that div? that's no Trans component -> t will return what ever your key simpleContent will return -> it's just a function returning a string...like basic i18next: https://www.i18next.com/essentials.html#accessing-keys |
@jamuhl I mean the strong element, which has a t() function inside:
|
that's same as |
Yes, I get that part. I was just wondering how this is combined into a single JSON string. Can you please provide the full JSON that covers both the Trans component and the nameTitle key? Please include keys and values that work with:
Thanks man |
{
"userMessagesUnread": "Hello <1><0>{{name}}</0></1>, you have <3>{{count}}</3> unread message. <5>Go to messages</5>",
"nameTitle": "Whatever title should be on the strong element",
"simpleContent": "Some content not related to the Trans component and gets shown in the div"
} |
OK, I see. Not super intuitive, for me at least! Thanks a lot for your patience explaining it :) |
Just out of curiosity...what would be an intuitive string output for translations for:
|
I haven't really thought it through of course, but I wouldn't allow t() inside a Trans component. So that would require an extra assignment. And also: make the JSON identical to the actual child (so no number tags). Not sure if this has issues, but it would be must easier to work with and maintain. |
-> not sure but you miss - making it identical might be funny for devs...but no win for translators...same for the additional t call - it's good for the translator...making that construct more complex in the json strings makes it just worse to translate. |
True, better make it hard for devs :) |
not that hard...just look at each node not a complete rich component. Even more as dev you don't have to care...just turn on saveMissing and have a backend plugin do the heavy work...like https://www.youtube.com/watch?v=9NOzJhgmyQE no need to even think about the Trans components final string output. |
check, you are right. Once you get it (and read the docs) it's simple :) Thanks! |
is the nested <1><0> working ?
{{name}} should be bold then italic, however, it becomes simply not shown. |
@jackie-onai I don't see there's a translation for your |
@jackie-onai should be (not tested)
why not just set debug: true or read: https://react.i18next.com/latest/trans-component#how-to-get-the-correct-translation-string |
I have one React component that involves translation within tags so I use
<Trans>
component to perform the translation, but apparently it's not detecting the tags properly and rendered a glitched translation. My component have one link but it was rendered in<strong>
tag, and tag<0>
was repeated instead of rendering the<strong>
tag. Could it be the guessing beingshifted
in some way?The text was updated successfully, but these errors were encountered: