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

Add Rich Text Support to SolidJS i18n #715

Open
0-don opened this issue Oct 31, 2024 · 5 comments
Open

Add Rich Text Support to SolidJS i18n #715

0-don opened this issue Oct 31, 2024 · 5 comments

Comments

@0-don
Copy link

0-don commented Oct 31, 2024

Describe The Problem To Be Solved

Currently, we can't add links or styled text inside i18n translations in SolidJS. We need a simple way to add components like or tags within our translated text, similar to how next-intl does it.

Suggest A Solution

Add a simple t.rich() method that allows mapping custom tags to Solid components:

Example usage:

{
  "message": "Please refer to <guidelines>{name}</guidelines>"
}

const t = useTranslations();

t.rich('message', {
  guidelines: (text) => <A href="/guidelines">{text}</A>
  name: "the guidelines"
})

Key features:

  • Support basic tag mapping
  • Work with existing SolidJS components
  • Keep the same simple API as regular translations

This would give us an easy way to add links and formatting to our translations while keeping the code clean and maintainable.

@thetarnav
Copy link
Member

I like the simple concept
Maybe not that rich here is a method on whatever t is
If this could be done as a separate helper I wouldn't really mind
Don't see a way to make this type-safe though
At least not without codegen
So the "maintainable" part is up for debate

@0-don
Copy link
Author

0-don commented Oct 31, 2024

Thanks for the feedback @thetarnav

You're right about the implementation concerns. I think we could start simple with just basic runtime validation of the tags and mapping object. No need to overcomplicate things with type safety or codegen at this stage.

The separate helper approach you suggested makes sense too. The main goal is just to enable basic rich text support in translations.

@atk
Copy link
Member

atk commented Nov 1, 2024

I like the idea of a resolveTags helper. Not being type safe may be a drawback, but not one that should concern us. We should use a callback function that emits a warning in DEV and strips the tags in prod.

@joaofranciscoguarda
Copy link

This is a must need. Not the best/easiest way to implement it, but some feature is better than no feature

@0-don
Copy link
Author

0-don commented Nov 6, 2024

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

4 participants