Class: JavascriptI18n::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/javascript_i18n/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lib_path, output_path, output_style = :merged) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
9
10
# File 'lib/javascript_i18n/builder.rb', line 5

def initialize(lib_path, output_path, output_style = :merged)
  self.lib_path = lib_path
  self.output_path = output_path
  self.output_style = output_style
  I18n.backend.send(:init_translations)
end

Instance Attribute Details

#lib_pathObject

Returns the value of attribute lib_path.



3
4
5
# File 'lib/javascript_i18n/builder.rb', line 3

def lib_path
  @lib_path
end

#output_pathObject

Returns the value of attribute output_path.



3
4
5
# File 'lib/javascript_i18n/builder.rb', line 3

def output_path
  @output_path
end

#output_styleObject

Returns the value of attribute output_style.



3
4
5
# File 'lib/javascript_i18n/builder.rb', line 3

def output_style
  @output_style
end

Instance Method Details

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/javascript_i18n/builder.rb', line 12

def run
  lib = File.read(File.join(lib_path, "i18n.js")) if output_style == :merged
  I18n.backend.send(:translations).each do |key, value|
    File.open(File.join(output_path, "#{key}.js"), "w") do |file|
      if output_style == :merged
        file.puts(lib)
        file.puts("\n")
      end
      file.puts("I18n.locale = I18n.locale || \"#{key}\";")
      file.puts("I18n.translations = I18n.translations || #{value.to_json};")
    end
  end
end