Class: I18nliner::Commands::Dump

Inherits:
GenericCommand show all
Defined in:
lib/i18nliner/commands/dump.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GenericCommand

run, #success?

Methods included from BasicFormatter

#green, #red

Constructor Details

#initialize(options) ⇒ Dump

Returns a new instance of Dump.



9
10
11
12
13
14
# File 'lib/i18nliner/commands/dump.rb', line 9

def initialize(options)
  super
  @translations = @options[:translations]
  @yml_file = @options[:file] ||
    File.join(I18nliner.base_path, "config", "locales", "generated", "#{I18n.default_locale}.yml")
end

Instance Attribute Details

#yml_fileObject (readonly)

Returns the value of attribute yml_file.



7
8
9
# File 'lib/i18nliner/commands/dump.rb', line 7

def yml_file
  @yml_file
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
# File 'lib/i18nliner/commands/dump.rb', line 16

def run
  FileUtils.mkdir_p File.dirname(yml_file)
  File.open(yml_file, "w") do |file|
    file.write({I18n.default_locale.to_s => @translations}.ya2yaml(:syck_compatible => true))
  end
  puts "Wrote default translations to #{yml_file}" unless @options[:silent]
end