Skip to content

Commit

Permalink
Only t calls can use relative keys, not I18n.t
Browse files Browse the repository at this point in the history
Tackles #106
  • Loading branch information
glebm committed Aug 8, 2015
1 parent a482c68 commit 8590a22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/i18n/tasks/scanners/ruby_ast_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ def send_node_to_key_occurrence(send_node, method_name, location: send_node.loc)
extract_string(default_arg_node.children[1])
end
end
[absolute_key(key, location.expression.source_buffer.name, method_name),
range_to_occurrence(location.expression, default_arg: default_arg)]
full_key = if send_node.children[0].nil?
# Relative keys only work if called via `t()` but not `I18n.t()`:
absolute_key(key, location.expression.source_buffer.name, method_name)
else
key
end
[full_key, range_to_occurrence(location.expression, default_arg: default_arg)]
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def show()

# default arg
I18n.t('default_arg', default: 'Default Text')

# only `t()` calls can use relative keys and not `I18n.t()` calls.
I18n.t('.not_relative')
end

def update
Expand Down
1 change: 1 addition & 0 deletions spec/i18n_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
index.my_custom_scanner.title
magic_comment
default_arg
.not_relative
)
}
let (:expected_missing_keys_diff) {
Expand Down

0 comments on commit 8590a22

Please sign in to comment.