Skip to content

Commit

Permalink
Handle controller name with multiple words
Browse files Browse the repository at this point in the history
Currently relative keys in app/controllers/admin_users_controller.rb are
resolved as `admin.KEY`.

With this fix they'll be resolved as `admin_users.KEY` correctly.
  • Loading branch information
yujinakayama committed Mar 2, 2015
1 parent f6ad75b commit 7a8585e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/i18n/tasks/scanners/relative_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def prefix(normalized_path, roots, options = {})
file_name = normalized_path.gsub(%r(#{path_root(normalized_path, roots)}/|(\.[^/]+)*$), '')

if options[:closest_method].present?
"#{file_name.split('_').first}.#{options[:closest_method]}".tr('/', '.')
controller_name = file_name.sub(/_controller$/, '')
"#{controller_name}.#{options[:closest_method]}".tr('/', '.')
else
file_name.tr('/', '.').gsub(%r(\._), '.')
end
Expand Down
13 changes: 13 additions & 0 deletions spec/relative_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
expect(key).to eq('users.create.success')
end

context 'multiple words in controller name' do
it 'works' do
key = scanner.absolutize_key(
'.success',
'app/controllers/admin_users_controller.rb',
%w(app/controllers),
'create'
)

expect(key).to eq('admin_users.create.success')
end
end

context 'nested in module' do
it 'works' do
key = scanner.absolutize_key(
Expand Down

0 comments on commit 7a8585e

Please sign in to comment.