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

Improve localization helpers #842

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

jclusso
Copy link
Contributor

@jclusso jclusso commented Feb 18, 2024

  • Added support for relative translation keys (ex: t('.foo')).
  • Added support for automatically marking translation keys ending with _html as html_safe.
  • Renamed methods to translate and localize with aliases of t and l.
  • Added tests.

This is a 🙋 feature or enhancement.
This is a 🔦 documentation change.

Closes #837

- Added support for relative translation keys (ex: `t('.foo')`).
- Added support for automatically marking translation keys ending with `_html` as `html_safe`.
- Renamed methods to `translate` and `localize` with aliases of `t` and `l`.
- Added tests
@jaredcwhite
Copy link
Member

This looks really good @jclusso!

I would like to avoid adding the dependency on Active Support here (since we're generally headed in the opposite direction). Looking at the code being called, it seems fairly self-contained:

https://github.com/rails/rails/blob/main/activesupport/lib/active_support/html_safe_translation.rb

If you're feeling particularly ambitious, I might ask you to write a greenfield take on this functionality—otherwise, I'm completely fine with vendoring this into its own module file somewhere and a commented link to the original code on GH. LMK what you think, I'm good with either option. TY 🙏🏻

@jclusso
Copy link
Contributor Author

jclusso commented Feb 22, 2024

Thanks @jaredcwhite!

I'm not super familiar with how the whole string safety thing works and I wouldn't feel comfortable blindly ripping this out of Active Support. I feel it's also worth noting that Active Support is one of the top 10 most downloaded gems and it really seems like a poor use of my time to reinvent the wheel. I personally can't justify that since I have a limited amount of time I can put into OS projects and I much rather put it into something that moves the needle. I hope you can understand.

It would be a shame if that was a deal breaker for this PR since I think a lot of people would find this useful.

@jaredcwhite jaredcwhite merged commit b75f286 into bridgetownrb:main Feb 22, 2024
4 checks passed
@jaredcwhite
Copy link
Member

I'll go ahead and merge and rewrite that dependency. We're just not going to be relying on any new Active Support functionality going forward.

Thanks for the PR.

@jclusso jclusso deleted the improve_localization_helpers branch February 22, 2024 13:53
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 this pull request may close these issues.

feat: _html translation key automatic safety support
2 participants