Module: Tcl::Msgcat
- Defined in:
- lib/tcl/msgcat.rb,
lib/tcl/msgcat/parser.rb,
lib/tcl/msgcat/catalog.rb,
lib/tcl/msgcat/version.rb,
lib/tcl/msgcat/renderer.rb,
lib/tcl/msgcat/paddable_string.rb
Defined Under Namespace
Modules: PaddableString
Classes: Catalog, Parser, Renderer
Constant Summary
collapse
- VERSION =
"1.0.4"
Class Method Summary
collapse
Class Method Details
.compile(source, target) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/tcl/msgcat.rb', line 42
def compile(source, target)
raise ArgumentError, "Not a directory: #{source}" unless File.directory? source
raise ArgumentError, "Not a directory: #{target}" unless File.directory? target
Dir["#{source}/*.json"].each do |src|
dst = File.basename(src, ".json")+".msg"
print "Compiling #{src} to #{target}/#{dst}... "
msgs = JSON.parse(File.read(src))
renderer = Tcl::Msgcat::Renderer.new(msgs).render
File.write("#{target}/#{dst}") {|f| f.write renderer.to_s }
puts "done"
end
end
|
.merge(root_file, translation_files = []) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/tcl/msgcat.rb', line 25
def merge(root_file, translation_files=[])
if translation_files.is_a? String
translation_files = Dir[translation_files]
end
root = Tcl::Msgcat::Catalog.load(root_file)
translation_files.each do |file|
next if File.basename(file) == File.basename(root_file)
print "Merging new translations into #{file}... "
catalog = Tcl::Msgcat::Catalog.load(file)
catalog.merge!(root)
File.open(file, "w") {|f| f.write catalog.to_json }
puts "done"
end
end
|
.parse(msgcat_file) ⇒ Object
15
16
17
|
# File 'lib/tcl/msgcat.rb', line 15
def parse(msgcat_file)
Tcl::Msgcat::Parser.new(msgcat_file).parse
end
|
.render(json_file) ⇒ Object
19
20
21
22
23
|
# File 'lib/tcl/msgcat.rb', line 19
def render(json_file)
raise ArgumentError, "File not found: #{json_file}" unless File.exist? json_file
msgs = JSON.parse(File.read(json_file))
Tcl::Msgcat::Renderer.new(msgs).render
end
|