Class: I18nYamlEditor::App

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_yaml_editor/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ App

Returns a new instance of App.



12
13
14
15
16
# File 'lib/i18n_yaml_editor/app.rb', line 12

def initialize path
  @path = File.expand_path(path)
  @store = Store.new
  I18nYamlEditor.app = self
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



18
19
20
# File 'lib/i18n_yaml_editor/app.rb', line 18

def store
  @store
end

Instance Method Details

#load_translationsObject



31
32
33
34
35
36
37
# File 'lib/i18n_yaml_editor/app.rb', line 31

def load_translations
  files = Dir[@path + "/**/*.yml"]
  files.each {|file|
    yaml = YAML.load_file(file)
    store.from_yaml(yaml, file)
  }
end

#save_translationsObject



39
40
41
42
43
44
# File 'lib/i18n_yaml_editor/app.rb', line 39

def save_translations
  files = store.to_yaml
  files.each {|file, yaml|
    File.open(file, "w", encoding: "utf-8") {|f| f << yaml.to_yaml}
  }
end

#startObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/i18n_yaml_editor/app.rb', line 20

def start
  $stdout.puts " * Loading translations from #{@path}"
  load_translations

  $stdout.puts " * Creating missing translations"
  store.create_missing_keys

  $stdout.puts " * Starting web editor at port 5050"
  Rack::Server.start :app => Web, :Port => 5050
end