module Tcl::Msgcat
Constants
- VERSION
Public Class Methods
compile(source, target)
click to toggle source
# File lib/tcl/msgcat.rb, line 53 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}... " begin File.open("#{target}/#{dst}", "w") {|f| f.write render(src) } puts "done" rescue ArgumentError => e puts e.message end end end
merge(root_file, translation_files=[])
click to toggle source
# File lib/tcl/msgcat.rb, line 28 def merge(root_file, translation_files=[]) if translation_files.is_a? String translation_files = Dir[translation_files] end begin root = Tcl::Msgcat::Catalog.load(root_file) rescue MultiJson::ParseError => e raise MultiJson::ParseError, "Failed to parse #{root_file}: #{e.message}" end translation_files.each do |file| begin 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" rescue MultiJson::ParseError => e raise MultiJson::ParseError, "Failed to parse #{file}: #{e.message}" end end end
parse(msgcat_file)
click to toggle source
# File lib/tcl/msgcat.rb, line 17 def parse(msgcat_file) Tcl::Msgcat::Parser.new(msgcat_file).parse end
render(json_file)
click to toggle source
# File lib/tcl/msgcat.rb, line 21 def render(json_file) raise ArgumentError, "File not found: #{json_file}" unless File.exist? json_file msgs = MultiJson.load(File.read(json_file)) lang = File.basename(json_file, File.extname(json_file)) Tcl::Msgcat::Renderer.new(msgs, lang).render end