Skip to content

Rubocop rule to prevent assigning translations to constants

Description of the proposal

This MR adds a rubocop rule to prevent assigning translated texts to constants.

Pattern to detect:

class MySerializer
  KEYS = {
    key_1: s_('Hello')
  }.freeze
end

Unfortunately this is not possible when we're dealing with translated text, since the translation will be evaluated when the class is loaded for the first time and it translates the text to the default_locale.

KEYS[:key_1] will always contain the English translation, no matter what your current locale is.

Check-list

  • Make sure this MR enables a static analysis check rule for new usage but ignores current offenses
  • Mention this proposal in the relevant Slack channels (e.g. #development, #backend, #frontend)
  • The MR doesn't have significant objections, and is getting a majority of 👍 vs 👎 (remember that we don't need to reach a consensus)
  • [-] Create a follow-up issue to fix the current offenses as a separate iteration (fixed within the MR)
  • Follow the review process as usual
  • Once approved and merged by a maintainer, mention it again:
    • In the relevant Slack channels (e.g. #development, #backend, #frontend)
    • (Optional depending on the impact of the change) In the Engineering Week in Review

/label Engineering Productivity ~"Style decision" development guidelines ~"static analysis"

Edited by Adam Hegyi

Merge request reports