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

Expose formatElements #948

Closed
testerez opened this issue Nov 30, 2022 · 6 comments · Fixed by #1213
Closed

Expose formatElements #948

testerez opened this issue Nov 30, 2022 · 6 comments · Fixed by #1213

Comments

@testerez
Copy link
Contributor

testerez commented Nov 30, 2022

What version of this package are you using?

next-translate@1.6.0

What problem do you want to solve?

I'm using next-translate to translate emails built with Mailing. Unfortunately, this does not allow me to user react context. This is why I rely on getT to provide a Translate function to my components.
It works well but I also need to translate texts including HTML tags. But unfortunately, Trans component relies on context so it does not work for me.

What do you think is the correct solution to this problem?

Either allow me to pass Translate function to Trans component so that it does not rely on useTranslation.
Or, simply expose formatElements so that I can use it directly.

Are you willing to submit a pull request to implement this change?

Yes

@aralroca
Copy link
Owner

Verify first if next-translate/lib/esm/formatElements or next-translate/lib/cjs/formatElements is solving this. After you verify it, we can do it public to be directly next-translate/formatElements

@testerez
Copy link
Contributor Author

Thanks @aralroca , it does work for me with either esm of cjs. Thouhg Typescript definitions are missing.

@aralroca
Copy link
Owner

Feel free to PR to add the Typescript definitions, and to do it public you can add this file here:

https://github.com/aralroca/next-translate/blob/master/package.json#L32

@testerez
Copy link
Contributor Author

Thanks, I'll do it when I find the time 👍

@aralroca
Copy link
Owner

@testerez do you already need formatElements? Feel free to comment and I will re-open the issue

@testerez
Copy link
Contributor Author

Sorry @aralroca , we can say I took my time on this one 😄

I'm still using that function in one of my projects and I'm currently importing it like this:

import formatElements from 'next-translate/lib/cjs/formatElements'

with this in a .d.ts:

declare module 'next-translate/lib/cjs/formatElements'

This works but is not typed...

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

Successfully merging a pull request may close this issue.

2 participants