Project

General

Profile

« Previous | Next » 

Revision eb6e0359

Added by Marc Dequènes over 14 years ago

  • ID eb6e0359e66f7e92e69b30eaa3795818d2e29ab0

[evol] translation rework: new mechanism to handle translated/untranslated strings, make use of translation parameters, moved I18n class, translations update

View differences:

bin/postman
#require 'socket'
require 'tempfile'
require 'shellwords'
require 'cyborghood/language'
require 'cyborghood/imap'
require 'cyborghood/mail'
require 'cyborghood/mail_order'
......
module CyborgHood
module PostmanHome
include GetText
include CHTranslation
bindtextdomain("cyborghood_postman", {:path => Config::L10N_DIR, :charset => "UTF-8"})
# not yet ready to be a real Cyborg
class Postman #< Cyborg
include GetText
include CHTranslation
def initialize
# load config
......
end
end
result_tag = report.ok? ? "SUCCESS" : "FAILURE"
logger.info "Processing result: #{result_tag} (#{report.error})"
result_msg = "Processing result: #{result_tag}"
result_msg += " (#{report.error.untranslated})" unless report.ok?
logger.info result_msg
i18n = I18n.instance
i18n.set_language_for_user(report.user)
......
unless report.ok?
if report.warn_sender
logger.info "Sending reply for rejected message"
intro = report.user ? sprintf(_("Hello %s,"), report.user.cn) : _("Hello,")
mail_reply = mail.create_simple_reject_reply(intro + "\n\n" + sprintf(
_("A message (ID: %s), apparently from you, was rejected for the following reason:"),
mail.message_id) + "\n " + _(report.error) + "\n" + mail_signature())
reply_intro = report.user ? _("Hello %{cn},", :cn =>report.user.cn) : _("Hello,")
mail_reply = mail.create_simple_reject_reply(reply_intro.to_s + "\n\n" +
_("A message (ID: %{id}), apparently from you, was rejected for the following reason:",
:id => mail.message_id).to_s + "\n " + report.error.to_s + "\n" + mail_signature())
mail_reply.deliver
end
msg.delete
......
order = MailOrder.parse(report.user, report.message)
result_tag = order.valid? ? "SUCCESS" : "FAILURE"
logger.info "Processing result: #{result_tag} (#{order.error})"
result_msg = "Processing result: #{result_tag}"
result_msg += " (#{order.error.untranslated})" unless order.valid?
logger.info result_msg
reply_intro = _("Hello %{cn},", :cn => order.user.cn)
unless order.valid?
logger.info "Sending reply for rejected order"
mail_reply = mail.create_simple_reject_reply(sprintf(_("Hello %s,"), order.user.cn) + "\n\n" +
sprintf(_("An order, in a message (ID: %s) from you, was rejected for the following reason:"),
mail.message_id) + "\n " + _(order.error) + "\n" + mail_signature())
mail_reply = mail.create_simple_reject_reply(reply_intro.to_s + "\n\n" +
_("An order, in a message (ID: %{id}) from you, was rejected for the following reason:",
:id => mail.message_id).to_s + "\n " + order.error.to_s + "\n" + mail_signature())
mail_reply.sign_and_crypt(order.user.keyFingerPrint)
mail_reply.deliver
msg.delete
......
# create transcript
logger.debug "Preparing reply"
reply_txt = sprintf(_("Hello %s,"), order.user.cn) + "\n\n"
reply_txt += _("Follows the transcript of your commands:") + "\n"
reply_txt = reply_intro.to_s + "\n\n"
reply_txt += _("Follows the transcript of your commands:").to_s + "\n"
reply_attachments = []
result_list.each do |result|
reply_txt += "> #{result.cmd}\n"
......
s = "\n" +
"-- \n" +
"#{CyborgHood::PRODUCT} v#{CyborgHood::VERSION}\n"
s += _("Contact eMail:") + " \"#{@config.contact.name}\" <#{@config.contact.email}>\n" if @config.contact.email
s += _("Contact URL:") + " #{@config.contact.url}\n" if @config.contact.url
s += _("Contact eMail:").to_s + " \"#{@config.contact.name}\" <#{@config.contact.email}>\n" if @config.contact.email
s += _("Contact URL:").to_s + " #{@config.contact.url}\n" if @config.contact.url
s
end
end
class CommandRunner
include GetText
include CHTranslation
def self.run(order)
result_list = []
......
rescue CyberError => e
result.message = e.message.capitalize + "."
rescue
logger.warn "Command crashed: " + $!
logger.error "Command crashed: " + $!
logger.error "Crash trace: " + $!.backtrace.join("\n")
result.message = _("Internal error. Administrator is warned.")
end
tag = result.ok ? "SUCCESS" :"FAILURE"
tag = result.ok ? "SUCCESS" : "FAILURE"
logger.debug "Command result: [#{tag}] #{result.message}"
else
logger.info "Invalid command detected: #{cmd.cmdline}"
result.message = cmd.parsing_errors.collect{|err| _(err) }.join("\n")
cmd.parsing_errors.collect{|err| logger.debug "Invalid command detected - reason: " + err.untranslated }
result.message = cmd.parsing_errors.collect{|err| err.to_s }.join("\n")
end
result_list << result
end
......
list = CyborgHood::DnsDomain.find_by_manager(user)
txt_list = list.collect{|z| z.cn }.sort.join(", ")
result.ok = true
result.message = sprintf(_("You are manager of the following zones: %s."), txt_list)
result.message = _("You are manager of the following zones: %{zone_list}.", :zone_list => txt_list)
when "GET"
return if cmdline.empty?
case cmdline.shift.upcase

Also available in: Unified diff