module I18n::Processes::KeyPatternMatching
Public Instance Methods
compile_key_pattern(key_pattern)
click to toggle source
convert pattern to regex In patterns:
* is like .* in regexs : matches a single key { a, b.c } match any in set, can use : and *, match is captured
# File lib/i18n/processes/key_pattern_matching.rb, line 25 def compile_key_pattern(key_pattern) return key_pattern if key_pattern.is_a?(Regexp) /\A#{key_pattern_re_body(key_pattern)}\z/ end
compile_patterns_re(key_patterns)
click to toggle source
one regex to match any
# File lib/i18n/processes/key_pattern_matching.rb, line 11 def compile_patterns_re(key_patterns) if key_patterns.blank? # match nothing MATCH_NOTHING else /(?:#{ key_patterns.map { |p| compile_key_pattern p } * '|' })/m end end
key_pattern_re_body(key_pattern)
click to toggle source
# File lib/i18n/processes/key_pattern_matching.rb, line 30 def key_pattern_re_body(key_pattern) key_pattern .gsub(/\./, '\.') .gsub(/\*/, '.*') .gsub(/:/, '(?<=^|\.)[^.]+?(?=\.|$)') .gsub(/\{(.*?)}/) { "(#{Regexp.last_match(1).strip.gsub(/\s*,\s*/, '|')})" } end