Sha256: 3edc6db1b3aa01ec20a5f0094a001cf7f56ac1a4a6236a14579650a048692715
Contents?: true
Size: 1.52 KB
Versions: 4
Compression:
Stored size: 1.52 KB
Contents
require 'gettext/tools' require 'spiderfw/templates/blocks/text' module Spider; module I18n module JavascriptParser module_function GettextRegexp = /\W_\(['"]([^\)'"]+)['"](,\s*[^\)]+\s*)*\)/ def target?(file) File.extname(file) == '.js' end def parse(file, ary) f = File.new(file) cnt = 0 my_ary = [] f.each_line do |line| cnt += 1 scanner = ::StringScanner.new(line) while scanner.scan_until(GettextRegexp) str = scanner.matched str =~ GettextRegexp found = false (ary+my_ary).each do |msg| if (msg[0] == $1) msg << "#{file}:#{cnt}" found = true break end end my_ary << [$1, "#{file}:#{cnt}"] unless found end end f.close unless my_ary.empty? dir = File.dirname(file) name = File.basename(file, '.js') i18n_file = File.join(dir, "#{name}.i18n.json") File.open(i18n_file, 'w') do |f| f << my_ary.collect{ |a| a[0] }.to_json end end return ary + my_ary end end ::GetText::RGetText.add_parser(JavascriptParser) end; end
Version data entries
4 entries across 4 versions & 1 rubygems