module I18n::Tasks::Data::Adapter::YamlAdapter

Constants

EMOJI_REGEX
TRAILING_SPACE_REGEX

Public Class Methods

dump(tree, options) click to toggle source

@return [String]

# File lib/i18n/tasks/data/adapter/yaml_adapter.rb, line 23
def dump(tree, options)
  strip_trailing_spaces(restore_emojis(tree.to_yaml(options || {})))
end
parse(str, options) click to toggle source

@return [Hash] locale tree

# File lib/i18n/tasks/data/adapter/yaml_adapter.rb, line 13
def parse(str, options)
  if YAML.method(:load).arity.abs == 2
    YAML.safe_load(str, **(options || {}), permitted_classes: [Symbol], aliases: true)
  else
    # older jruby and rbx 2.2.7 do not accept options
    YAML.load(str)
  end
end
restore_emojis(yaml) click to toggle source

@return [String]

# File lib/i18n/tasks/data/adapter/yaml_adapter.rb, line 28
def restore_emojis(yaml)
  yaml.gsub(EMOJI_REGEX) { |m| [m[-8..].to_i(16)].pack('U') }
end
strip_trailing_spaces(yaml) click to toggle source

@return [String]

# File lib/i18n/tasks/data/adapter/yaml_adapter.rb, line 33
def strip_trailing_spaces(yaml)
  yaml.gsub(TRAILING_SPACE_REGEX, '')
end