Project

General

Profile

« Previous | Next » 

Revision 7cae0102

Added by Marc Dequènes over 15 years ago

  • ID 7cae0102718dcd9e194e04ea551c5759700b331d

[evol] added gettext support using user prefered langage

View differences:

postman
result = OpenStruct.new
result.cmd = cmdstr
result.ok = false
result.message = "Command not recognized."
result.message = _("Command not recognized.")
result.refs = nil
end
rescue CyberError => e
......
result = OpenStruct.new
result.cmd = cmdstr
result.ok = false
result.message = "Internal error. Administrator is warned."
result.message = _("Internal error. Administrator is warned.")
result.refs = nil
end
......
list = CyborgHood::DnsDomain.find_by_manager(user)
txt_list = list.collect{|z| z.cn }.sort.join(", ")
result.ok = true
result.message = "You are manager of the following zones: #{txt_list}."
result.message = _("You are manager of the following zones: %s.") + txt_list
when "GET"
return if cmdline.empty?
case cmdline.shift.upcase
......
dom = CyborgHood::DnsDomain.new(zone)
unless dom.hosted?
result.message = "This zone is not hosted here."
result.message = ("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = "You are not allowed to manage this zone."
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = CyborgHood::Services::DNS.new(zone)
result.ok = true
result.message = "Requested zone content attached."
result.message = _("Requested zone content attached.")
zone_ref = {:content => srv_dns.read_zone, :filename => "dnszone_#{zone}.txt"}.to_ostruct
result.refs = [zone_ref]
end
......
zone = cmdline.shift.downcase
dom = CyborgHood::DnsDomain.new(zone)
unless dom.hosted?
result.message = "This zone is not hosted here."
result.message = _("This zone is not hosted here.")
return result
end
unless dom.managed_by? user
result.message = "You are not allowed to manage this zone."
result.message = _("You are not allowed to manage this zone.")
return result
end
srv_dns = CyborgHood::Services::DNS.new(zone)
......
return unless content_ref =~ /^@(\d+)$/
part_ref = $1.to_i
unless (1..refs.size).include? part_ref
result.message = "Attachment number not found."
result.message = _("Attachment number not found.")
return result
end
part = refs[part_ref]
unless part.content_type == "text/plain"
result.message = "Attachment has wrong content-type."
result.message = _("Attachment has wrong content-type.")
return result
end
......
dns_result = srv_dns.check_zone_file(f.path)
unless dns_result.ok
result.message = "Invalid zone data."
result.message = _("Invalid zone data.")
f.close!
return result
end
logger.debug "New serial: #{dns_result.serial}"
# allow new serial or missing serial (to allow creating a new zone or replacing a broken zone)
unless current_serial.nil? or dns_result.serial > current_serial
result.message = "Zone serial is not superior to current serial."
result.message = _("Zone serial is not superior to current serial.")
f.close!
return result
end
......
if srv_dns.reload_zone
logger.debug "zone reloaded"
result.ok = true
result.message = "Zone updated."
result.message = _("Zone updated.")
else
logger.warn "zone reload failed, replacing old content"
srv_dns.replace_zone_with_backup
result.message = "Internal error. Administrator is warned."
result.message = _("Internal error. Administrator is warned.")
end
rescue
logger.warn "Writing zone file failed"
......
result_tag = order.ok ? "SUCCESS" : "FAILURE"
logger.info "Processing result: #{result_tag} (#{order.message})"
logger.info "Extra processing information: " + order.system_message if order.system_message
if order.user and order.user.preferredLanguage
locale = order.user.preferredLanguage
else
locale = "en"
end
unless order.ok
if order.warn_sender
logger.info "Sending reply for rejected message"
mail_reply = mail.create_simple_reject_reply("A message (ID: #{mail.message_id}), apparently from you," +
" was rejected for the following reason:\n #{order.message}")
" was rejected for the following reason:\n #{_(order.message)}")
mail_reply.deliver
end
msg.delete
......
# create transcript
logger.debug "Preparing reply"
reply_txt = "Hello #{order.user.cn},\n\n"
reply_txt += order.message + "\n\n" if order.message
reply_txt += "Follows the transcript of your commands:\n"
reply_txt = sprintf(_("Hello %s,"), order.user.cn) + "\n\n"
reply_txt += _(order.message) + "\n\n" if order.message
reply_txt += _("Follows the transcript of your commands:") + "\n"
reply_attachments = []
result_list.each do |result|
reply_txt << "> #{result.cmd}\n"

Also available in: Unified diff