Skip to content

Commit

Permalink
stricter dynamic key matching #75
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Jul 22, 2014
1 parent 620a28f commit ee6c572
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/tasks/key_pattern_matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def key_pattern_re_body(key_pattern)
def key_match_pattern(k)
@key_match_pattern ||= {}
@key_match_pattern[k] ||= begin
"#{k.gsub(KEY_INTERPOLATION_RE, '*')}#{'*' if k.end_with?('.')}"
"#{k.gsub(KEY_INTERPOLATION_RE, ':')}#{':' if k.end_with?('.')}"
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/i18n/tasks/used_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def used_in_expr?(key)
# keys in the source that end with a ., e.g. t("category.#{cat.i18n_key}") or t("category." + category.key)
def expr_key_re
@expr_key_re ||= begin
patterns = used_key_names.select { |k| key_expression?(k) }.map { |k| key_match_pattern(k) }
patterns = used_key_names.select { |k| key_expression?(k) }.map { |k|
pattern = key_match_pattern(k)
# disallow patterns with no keys
next if pattern =~ /\A(:\.)*:\z/
pattern
}.compact
compile_key_pattern "{#{patterns * ','}}"
end
end
Expand Down
3 changes: 2 additions & 1 deletion templates/config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# i18n-tasks find and manage missing and unused translations ⚙ https://github.com/glebm/i18n-tasks
# i18n-tasks finds and manages missing and unused translations ⚙ https://github.com/glebm/i18n-tasks

base_locale: en
## i18n-tasks detects locales automatically from the existing locale files
Expand Down Expand Up @@ -62,6 +62,7 @@ search:

## Google Translate
# translation:
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
# api_key: "AbC-dEf5"

## Consider these keys not missing
Expand Down

0 comments on commit ee6c572

Please sign in to comment.