module TranslationIO::YamlEntry

Constants

IGNORED_KEY_PREFIXES
LOCALIZATION_KEY_PREFIXES

Public Class Methods

from_locale?(key, locale) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 29
def from_locale?(key, locale)
  key.present? && key.start_with?("#{locale}.")
end
ignored?(key) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 33
def ignored?(key)
  key.present? && ignored_key_prefixes.any? { |prefix| key_without_locale(key).match(/^#{Regexp.escape(prefix)}\b/) != nil }
end
localization?(key, value) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 37
def localization?(key, value)
  key.present? && (localization_prefix?(key) || (!string?(key, value) && !value.nil?))
end
localization_prefix?(key) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 41
def localization_prefix?(key)
  localization_key_prefixes.any? do |prefix|
    key_without_locale(key).match(/^#{Regexp.escape(prefix)}\b/) != nil
  end
end
string?(key, value) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 25
def string?(key, value)
  key.present? && value.is_a?(String)
end

Private Class Methods

ignored_key_prefixes() click to toggle source
# File lib/translation_io/yaml_entry.rb, line 57
def ignored_key_prefixes
  if TranslationIO.config
    IGNORED_KEY_PREFIXES + TranslationIO.config.ignored_key_prefixes
  else
    IGNORED_KEY_PREFIXES
  end
end
key_without_locale(key) click to toggle source
# File lib/translation_io/yaml_entry.rb, line 65
def key_without_locale(key)
  key.split('.', 2).last
end
localization_key_prefixes() click to toggle source
# File lib/translation_io/yaml_entry.rb, line 49
def localization_key_prefixes
  if TranslationIO.config
    LOCALIZATION_KEY_PREFIXES + TranslationIO.config.localization_key_prefixes
  else
    LOCALIZATION_KEY_PREFIXES
  end
end