mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29887 from willnet/generator-suggestion-locale
Fix generator suggestion raise error when I18n.available_locales don’t include :en
This commit is contained in:
commit
858baa099b
2 changed files with 15 additions and 1 deletions
|
@ -274,8 +274,9 @@ module Rails
|
|||
else
|
||||
options = sorted_groups.flat_map(&:last)
|
||||
suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
|
||||
suggestions.map! { |s| "'#{s}'" }
|
||||
msg = "Could not find generator '#{namespace}'. ".dup
|
||||
msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n"
|
||||
msg << "Maybe you meant #{ suggestions[0...-1].join(', ')} or #{suggestions[-1]}\n"
|
||||
msg << "Run `rails generate --help` for more options."
|
||||
puts msg
|
||||
end
|
||||
|
|
|
@ -36,6 +36,19 @@ class GeneratorsTest < Rails::Generators::TestCase
|
|||
assert_match "Maybe you meant 'migration'", output
|
||||
end
|
||||
|
||||
def test_generator_suggestions_except_en_locale
|
||||
orig_available_locales = I18n.available_locales
|
||||
orig_default_locale = I18n.default_locale
|
||||
I18n.available_locales = :ja
|
||||
I18n.default_locale = :ja
|
||||
name = :tas
|
||||
output = capture(:stdout) { Rails::Generators.invoke name }
|
||||
assert_match "Maybe you meant 'task', 'job' or", output
|
||||
ensure
|
||||
I18n.available_locales = orig_available_locales
|
||||
I18n.default_locale = orig_default_locale
|
||||
end
|
||||
|
||||
def test_generator_multiple_suggestions
|
||||
name = :tas
|
||||
output = capture(:stdout) { Rails::Generators.invoke name }
|
||||
|
|
Loading…
Reference in a new issue