Internationalization linter for your Ruby on Rails projects.
All you have to do is run the following command:
$ gem install i18n_linter
If you want to install using bundler
, add this to the Gemfile
under the development
group:
gem 'i18n_linter', require: false
Just type i18n_linter
in a Ruby on Rails project's folder and watch the strings that could be internationalized. Note: only strings in ruby files will be reported.
$ cd my/ruby_on_rails/project
$ i18n_linter [options]
The available options are:
-f PATTERN, --files=PATTERN Pattern to find files, default: -f '**/*.rb'
-o FILE, --out=FILE, Write output to a file instead of STDOUT
For example:
$ i18n_linter -f users_controller.rb
$ i18n_linter -f app/controllers/**/*.rb -o i18n_linter_output.txt
The behavior of I18nLinter can be controlled via the .i18n_linter.yml
configuration file.
It's possible to enable or disable Rules and exclude files from the validations as follows:
Linter:
Include:
- '**/*.rb'
Exclude:
- 'spec/**/*'
Rules:
Uppercase:
Enabled: true
MiddleSpace:
Enabled: false
Imagine a source file sample.rb containing:
class UserController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
def show
@user = User.find(params[:id])
end
private
def render_not_found
render json: { error: "Couldn't find the record" }, status: :not_found
end
end
I18nLinter will return the following warnings in this file:
$ i18n_linter -f sample.rb
sample.rb:11:26
10: def render_not_found
11: render json: { error: "Couldn't find the record" }, status: :not_found
12: end
----------------
Bug reports (please use Issues) and pull requests are welcome on GitHub at https://github.com/rootstrap/i18n_linter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
I18nLinter is maintained by Rootstrap with the help of our contributors.