base_dir = File.dirname(File.expand_path(__FILE__)) Dir.glob(File.join(base_dir, 'original','*.js.orig')).each do |orig_file| content = File.read(orig_file) locale = File.basename(orig_file)[0,2] content.gsub!(/^ /, ' ') content.sub!(/(jQuery|\$).extend\( (jQuery|\$).fn.pickadate.defaults, /, "$pickadate_translations['#{locale}'] = ") content.sub!(/format: '([^']+)',$/){ "format: 'yyyy-mm-dd',\n displayFormat: '#{Regexp.last_match[1]}',"} content.sub! '});', '};' content.sub! "formatSubmit: 'yyyy/mm/dd'", "formatSubmit: 'yyyy-mm-dd'" File.open(File.join(base_dir, "#{locale}.js"), 'w+'){|f| f.puts content} end