Skip to content

Add hover on i18n translations #640

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

domingo2000
Copy link
Contributor

@domingo2000 domingo2000 commented Jul 27, 2025

First implementation for I18n support (#639)

How it works

  1. Attach file watcher for all translation files
  2. Add server request to reload translations on file changes. The reload is fast because does not need to reload the entire rails server, just the I18n.
  3. Add server request to get I18n translations for all locales available in the I18n backend.
  4. On hover of I18n.t("hello") key string argument, request the server all the translations available and provide hover info for that.

It address points 1 and 2 of the issue list:

  1. Read what the translation says. e.g., I18n.t("hello") returns en: "Hello World", es: "¡Hola Mundo!".
  2. Find out if a translation is missing.

And is usefull for updating and creating translations because it gives feedback that the used translations "is correct" because makes direct calls to the I18n backend while typing and hovering it. Warning if the translation is missing.

This gives the following experience:
Screencast from 2025-07-27 00-40-33.webm

@domingo2000 domingo2000 requested a review from a team as a code owner July 27, 2025 04:44
when "reload_i18n"
with_progress("rails-reload-i18n", "Reloading Ruby LSP Rails I18n") do
with_notification_error_handling(request) do
I18n.reload! if defined?(I18n) && I18n.respond_to?(:reload!)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is provided because other I18n backend maybe does not implement the reloading feature.

RunnerClient.any_instance.stubs(i18n: expected_response)

response = hover_on_source(<<~RUBY, { line: 0, character: 9 })
I18n.t("foo")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be just t if we consider that you could be inside Action View, but perhaps that is beyond the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its out of scope. This changes only support I18n.t("some-key") calls. With absolute key and string literal as argument.

To support t notation for ActionView, we need the context of which file is beign parsed and be able to complete the call of I18n in an ActionView context, or with the scope of that specific file. It could be a nice follow up if you want to help 👍🏻 .

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.

2 participants