{"id":24678121,"url":"https://github.com/rubocop/rubocop-i18n","last_synced_at":"2025-10-30T06:14:09.969Z","repository":{"id":54282594,"uuid":"99938920","full_name":"rubocop/rubocop-i18n","owner":"rubocop","description":"RuboCop rules for detecting and autocorrecting undecorated strings for i18n (gettext and rails-i18n)","archived":false,"fork":false,"pushed_at":"2025-03-03T12:32:26.000Z","size":215,"stargazers_count":45,"open_issues_count":7,"forks_count":18,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-07-21T23:47:02.042Z","etag":null,"topics":["gettext","i18n","rails-i18n","rubocop"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubocop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bbatsov","patreon":"bbatsov","open_collective":"rubocop","tidelift":"rubygems/rubocop","custom":"https://www.paypal.me/bbatsov"}},"created_at":"2017-08-10T15:37:58.000Z","updated_at":"2025-06-27T11:14:51.000Z","dependencies_parsed_at":"2025-01-21T01:26:51.670Z","dependency_job_id":"b7371c54-f692-4531-be9a-4774a7d8304a","html_url":"https://github.com/rubocop/rubocop-i18n","commit_stats":null,"previous_names":["rubocop/rubocop-i18n","puppetlabs/rubocop-i18n"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/rubocop/rubocop-i18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubocop","download_url":"https://codeload.github.com/rubocop/rubocop-i18n/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubocop%2Frubocop-i18n/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266785466,"owners_count":23983823,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gettext","i18n","rails-i18n","rubocop"],"created_at":"2025-01-26T13:04:02.559Z","updated_at":"2025-10-30T06:14:09.891Z","avatar_url":"https://github.com/rubocop.png","language":"Ruby","funding_links":["https://github.com/sponsors/bbatsov","https://patreon.com/bbatsov","https://opencollective.com/rubocop","https://tidelift.com/funding/github/rubygems/rubocop","https://www.paypal.me/bbatsov"],"categories":[],"sub_categories":[],"readme":"# Rubocop::I18n\n\n[![CI](https://github.com/rubocop/rubocop-i18n/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop-i18n/actions/workflows/rubocop.yml)\n\nA set of cops for detecting strings that need i18n decoration in your project.\n\nSupports the following framework styles:\n\n- gettext\n- rails-i18n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rubocop-i18n'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rubocop-i18n\n\n## Usage\n\nIn your `rubocop.yml`:\n\n```yaml\nplugins:\n - rubocop-i18n\n...\n# You *must* choose GetText or Rails-i18n style checking\n# If you want GetText-style checking\nI18n/GetText:\n  Enabled: true\nI18n/RailsI18n:\n  Enabled: false\n# If you want rails-i18n-style checking\nI18n/RailsI18n:\n  Enabled: true\nI18n/GetText:\n  Enabled: false\n# If you want custom control of all the cops\nI18n/GetText/DecorateString:\n  Enabled: false\n  # Disable the autocorrect\n  AutoCorrect: false\nI18n/GetText/DecorateFunctionMessage:\n  Enabled: false\nI18n/GetText/DecorateStringFormattingUsingInterpolation:\n  Enabled: false\nI18n/GetText/DecorateStringFormattingUsingPercent:\n  Enabled: false\nI18n/RailsI18n/DecorateString:\n  Enabled: false\n```\n\n\u003e [!NOTE]\n\u003e The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.\n\n## Cops\n\n### I18n/GetText/DecorateString\n\nThis cop is looks for strings that appear to be sentences but are not decorated.\nSentences are determined by the STRING_REGEXP.\n\n##### Error message thrown\n\n```\ndecorator is missing around sentence\n```\n\n##### Bad\n\n``` ruby\n\"Result is bad.\"\n```\n\n##### Good\n\n``` ruby\n_(\"Result is good.\")\n```\n\n##### Ignored\n``` ruby\n\"string\"\n\"A string with out a punctuation at the end\"\n\"a string that doesn't start with a capital letter.\"\n```\n\n### I18n/GetText/DecorateFunctionMessage\n\nThis cop looks for any raise or fail functions and checks that the user visible message is using gettext decoration with the _() function.\nThis cop makes sure the message is decorated, as well as checking that the formatting of the message is compliant according to the follow rules.\nThis cop supports autocorrecting of [Simple decoration of a message](#Simple-decoration-of-a-message). See the rubocop documentation on how to run autocorrect.\n\n#### Simple decoration of a message\n\nSimple message strings should be decorated with the _() function\n\n##### Error message thrown\n\n```\n'raise' function, message string should be decorated\n```\n\n##### Bad\n\n``` ruby\nraise(\"Warning\")\n```\n\n##### Good\n\n``` ruby\nraise(_(\"Warning\"))\n```\n\n#### Multi-line message\n\nThe message should not span multiple lines, it causes issues during the translation process.\n\n##### Error message thrown\n\n```\n'raise' function, message should not be a multi-line string\n```\n\n##### Bad\n\n``` ruby\nraise(\"this is a multi\" \\\n\"line message\")\n```\n\n##### Good\n\n``` ruby\nraise(_(\"this is a multi line message\"))\n```\n\n#### Concatenated message\n\nThe message should not concatenate multiple strings, it causes issues during translation and with the gettext.\n\n##### Error message thrown\n\n```\n'raise' function, message should not be a concatenated string\n```\n\n##### Bad\n\n``` ruby\nraise(\"this is a concatenated\" + \"message\")\n```\n\n##### Good\n\n``` ruby\nraise(_(\"this is a concatenated message\"))\n```\n\n#### Interpolated message\n\nThe message should be formated in this particular style. Otherwise it causes issues during translation and with the gettext gem.\n\n##### Error message thrown\n\n```\n'raise' function, message should use correctly formatted interpolation\n```\n\n##### Bad\n\n``` ruby\nraise(\"this is an interpolated message IE #{variable}\")\n```\n\n##### Good\n\n``` ruby\nraise(_(\"this is an interpolated message IE %{value0}\") % {value0: var,})\n```\n\n#### No decoration and no string detected\n\nThe raise or fail function does not contain any decoration, or a simple string\n\n##### Error message thrown\n\n```\n'raise' function, message should be decorated\n```\n\n##### Bad\n\n``` ruby\nraise(someOtherFuntioncall(foo, \"bar\"))\n```\n\n##### Good\n\nIn this raise or fail function, the message does not contain any decoration at all and the message is not a simple string. It may make sense to convert the message to a simple string. eg [Simple decoration of a message](#Simple-decoration-of-a-message).\nOr ignore this raise or fail function following this [How to ignore rules in code](#How-to-ignore-rules-in-code) section.\n\n### I18n/GetText/DecorateStringFormattingUsingInterpolation\n\nThis cop looks for decorated gettext methods _() and checks that all strings contained\nwithin do not use string interpolation '#{}'\n\n#### Simple decoration of a message\n\nSimple message strings should be decorated with the _() function\n\n##### Error message thrown\n\n```\n'_' function, message string should not contain #{} formatting\n```\n\n##### Bad\n\n``` ruby\nputs _(\"a message with a #{'interpolation'}\")\n```\n\n##### Good\n\n``` ruby\nputs _(\"a message that is %{type}\") % { type: 'translatable' }\n```\n\n### I18n/GetText/DecorateStringFormattingUsingPercent\n\nThis cop looks for decorated gettext methods _() and checks that all strings contained\nwithin do not use sprintf formatting '%s' etc\n\n##### Error message thrown\n\n```\n'_' function, message string should not contain sprintf style formatting (ie %s)\n```\n\n##### Bad\n\n``` ruby\nraise(_(\"Warning is %s\") % ['bad'])\n```\n\n##### Good\n\n``` ruby\nraise(_(\"Warning is %{value}\") % { value: 'bad' })\n```\n\n### I18n/RailsI18n/DecorateString\n\nThis cop looks for decorated rails-i18n methods.\n\n##### Error message thrown\n\n```\ndecorator is missing around sentence\n```\n\n##### Bad\n\n``` ruby\nraise(\"Warning is %s\" % ['bad'])\n```\n\n##### Good\n\n``` ruby\nraise(t(\"Warning is %{value}\") % { value: 'good' })\nraise(translate(\"Warning is %{value}\") % { value: 'good' })\nraise(I18n.t(\"Warning is %{value}\") % { value: 'good' })\n```\n\n### I18n/RailsI18n/DecorateStringFormattingUsingInterpolation\n\nThis cop looks for decorated rails-i18n methods like `t()` and `translate()` and checks that all strings contained\nwithin do not use string interpolation '#{}'\n\n#### Simple decoration of a message\n\nSimple message strings should be decorated with the t() function\n\n##### Error message thrown\n\n```\n't' function, message key string should not contain #{} formatting\n```\n\n##### Bad\n\n``` ruby\nputs t(\"path.to.key.with.#{'interpolation'}\")\n```\n\n##### Good\n\n``` ruby\nputs t(\"path.to.key.with.interpolation\")\n```\n\n## How to ignore rules in code\n\nIt may be necessary to ignore a cop for a particular piece of code. We follow standard rubocop idioms.\n``` ruby\nraise(\"We don't want this translated.\")                 # rubocop:disable I18n/GetText/DecorateString\nraise(\"We don't want this translated.\")                 # rubocop:disable I18n/RailsI18n/DecorateString\nraise(\"We don't want this translated\")                  # rubocop:disable I18n/GetText/DecorateFunctionMessage\nraise(_(\"We don't want this translated #{crazy}\")       # rubocop:disable I18n/GetText/DecorateStringFormattingUsingInterpolation)\nraise(_(\"We don't want this translated %s\") % ['crazy'] # rubocop:disable I18n/GetText/DecorateStringFormattingUsingPercent)\n```\n\n## Known Issues\n\nRubocop currently does not detect Heredoc style messages in functions correctly, which in turn prevents this plugin from detecting them correctly.\nNot all sprintf formatting strings are detected.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that allows you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which creates a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/rubocop/rubocop-i18n. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [RuboCop Community Code of Conduct](CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubocop%2Frubocop-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubocop%2Frubocop-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubocop%2Frubocop-i18n/lists"}