Module: I18n::Processes::Scanners::RubyKeyLiterals

Included in:
PatternMapper, PatternScanner
Defined in:
lib/i18n/processes/scanners/ruby_key_literals.rb

Constant Summary collapse

LITERAL_RE =
/:?".+?"|:?'.+?'|:\w+/
VALID_KEY_CHARS =
/(?:[[:word:]]|[-.?!:;À-ž])/
VALID_KEY_RE =
/^#{VALID_KEY_CHARS}+$/

Instance Method Summary collapse

Instance Method Details

#literal_reObject

Match literals:

  • String: ”, “#{}”

  • Symbol: :sym, :”, :“#{}”



10
11
12
# File 'lib/i18n/processes/scanners/ruby_key_literals.rb', line 10

def literal_re
  LITERAL_RE
end

#strip_literal(literal) ⇒ String

remove the leading colon and unwrap quotes from the key match

Parameters:

  • literal (String)

    e.g: “key”, ‘key’, or :key.

Returns:

  • (String)

    key



17
18
19
20
21
# File 'lib/i18n/processes/scanners/ruby_key_literals.rb', line 17

def strip_literal(literal)
  literal = literal[1..-1] if literal[0] == ':'
  literal = literal[1..-2] if literal[0] == "'" || literal[0] == '"'
  literal
end

#valid_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/i18n/processes/scanners/ruby_key_literals.rb', line 26

def valid_key?(key)
  key =~ VALID_KEY_RE && !key.end_with?('.')
end