Skip to content

Add go to definition to I18n translations #685

@domingo2000

Description

@domingo2000

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 Add hover on i18n translations #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions