Skip to content
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

Replace HTML tags tokens from translation #44

Open
AlexandrTsvetkov opened this issue May 23, 2023 · 9 comments
Open

Replace HTML tags tokens from translation #44

AlexandrTsvetkov opened this issue May 23, 2023 · 9 comments

Comments

@AlexandrTsvetkov
Copy link

AlexandrTsvetkov commented May 23, 2023

🚀 Feature Proposal

Implement Trans react component functionality for jquery

Let's assume that in translation I do have text like:
"userMessagesUnread": "Hello <1>{{name}}</1>, you have {{count}} unread message."

It would be nice if on client side code I can define by myself what kind of HTML tags I want to use for <1></1>
So, usage will be:

<p data-i18n="userMessagesUnread">
  Hello <strong>{{name}}</strong>, you have {{count}} unread message
</p>

Motivation

Using separation of concerns principle we don't need to store HTML tags directly in translations

@jamuhl
Copy link
Member

jamuhl commented May 23, 2023

https://github.com/i18next/jquery-i18next#set-innerhtml-attributes does already what you ask for

@AlexandrTsvetkov
Copy link
Author

@jamuhl Thanks for answer.
What do you think about adding additional information to docs with examples how to use it?

@jamuhl
Copy link
Member

jamuhl commented May 23, 2023

feel free to provide a PR improving the docs...(technically it's nothing else then setting innerHtml on an html element)

@AlexandrTsvetkov
Copy link
Author

AlexandrTsvetkov commented May 23, 2023

@jamuhl Yes, sure. Wanted to ask one more thing. Maybe I am doing something wrong, but as an output I got this html code

<p data-i18n="[html]userMessagesUnread">
Hello &lt;1&gt;Name<!--1-->, you have {{count}} unread message.
</p>

Which looks like in the browser:
image

Could you please advise me? Thanks!

adrai added a commit that referenced this issue May 23, 2023
@adrai
Copy link
Member

adrai commented May 23, 2023

Here you have an example:

<p data-i18n="[html]userMessagesUnread" data-i18n-options='{ "name": "John", "count": 3 }'>

@AlexandrTsvetkov
Copy link
Author

@adrai Thanks for providing link.
Unfortunately, in this example we use concrete tag <strong> directly in translation
What I wanted to achieve in to put in translation <1> tag as a placeholder and later define it in html code as I mentioned in the first post. Same as <Trans> component does from react library

"userMessagesUnread": "Hello <1>{{name}}</1>, you have {{count}} unread message."

<p data-i18n="userMessagesUnread">
  Hello <strong>{{name}}</strong>, you have {{count}} unread message
</p>

@adrai
Copy link
Member

adrai commented May 23, 2023

No, there is no Trans component for jquery-i18next

@AlexandrTsvetkov
Copy link
Author

@adrai Exactly, that's why this issue is the feature proposal :)

@adrai
Copy link
Member

adrai commented May 23, 2023

There's no plan for that. Feel free to contribute with a PR if you like to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants