Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
Created October 28, 2014 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugopeixoto/4d25cd9e3de17a599655 to your computer and use it in GitHub Desktop.
Save hugopeixoto/4d25cd9e3de17a599655 to your computer and use it in GitHub Desktop.
namespace :po do
desc "TODO"
task :create, [:name, :path] => :environment do |t, args|
r = Repository.create!(name: args[:name], path: File.expand_path(args[:path]))
tr_st = ActiveRecord::Base.connection.raw_connection.prepare(
"INSERT INTO translations (translation_file_id, msgid, msgstr, created_at, updated_at) VALUES(?, ?, ?, ?, ?);")
# 2012-03-19 08:00:16.463415
now = Time.now.strftime("%Y-%m-%d %H:%M:%S.%6N")
%x[find #{r.path} -name "*.po" -printf "%P\n"].split("\n").each do |filepath|
puts filepath
file_id = r.translation_files.create(filepath: filepath).id
GetPomo::PoFile.parse(File.read(r.path + "/" + filepath))[1..-1].each do |message|
case message.msgid
when String
tr_st.execute(file_id, message.msgid, message.msgstr, now, now)
when Array
(0...message.size).each do |i|
tr_st.execute(file_id, message[i].msgid, message[i].msgstr, now, now)
end
else
raise Exception
end
end
end
tr_st.close()
end
desc "TODO"
task :update => :environment do
Repository.all.each do |repo|
repo.update_translations
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment