Shopify / Shopify/ruby-lsp-rails

Add go to definition to I18n translations

Open
#685 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
688
Forks
44
PR merge metrics
No merged PRs in 30d

Description

When using I18n, it will be useful to have GoToDefinition support. Improving the developer experience when working with translations.

Examples:

  • I18n.t("some-key") in .erb and .rb file.
  • I18n.translate("some-key") in .erb and .rb file.

Both should go to the definition(s) of that translation(s)

Some considerations:

  1. Changes in the yaml files that have the translations should be considered, the definition must be synced between the I18n backend when their sources changes (exampel: if I change a yaml file es.yml, the go to definition should change too).
  2. I18n could have different/custom translation backends.

My take on this is that this could be implemented in the following way:

  1. Make I18n have the metadata of where is each translation located. This should be opt-in so we only turn it on in development mode, so now the translation I18n.t("key") gives the pair (value, source_location) instead of just the value. This could be done via contribution to I18n or monkey patching in this addon, i prefer the first aproach.
  2. Use the same strategy as #640 but use a new request that use this new metadata from the I18n running in the rails background process to get the source_location of the translation in the go_to_definition_request.

The key is easily accessible by the AST tree in the I18n.t("string") call.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the strategy from #640 and the AST handling for I18n.t and I18n.translate calls. Trace how go_to_definition_request communicates with the Rails background process and how translation locations could stay synced when YAML sources change. Done means supported calls can navigate to their translation definitions, including updated locations after source changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby, yaml
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.