lib/receipt/pdf.rb in receipt-0.1.2 vs lib/receipt/pdf.rb in receipt-0.1.3

- old
+ new

@@ -16,11 +16,10 @@ :id, :payer, :receiver, :amount, :date, - :currency, :description, :logo, :location, :locale, :filepath @@ -64,11 +63,13 @@ :amount, :payer, :receiver, :description ].each do |p| - @errors[p] = 'required param not found' if params.send(p).to_s.empty? + if params.send(p).to_s.empty? + @errors[p] = t('receipt.errors.required_param_not_found') + end end @errors.size == 0 end @@ -78,10 +79,13 @@ def mimetype 'application/pdf' end + def currency + params.currency || t('receipt.currency') + end private def generate valid? @@ -94,28 +98,28 @@ after_receipt_box.call if after_receipt_box end def header pad(10) do - text(t(:receipt).upcase, align: :center, style: :bold, size: 20) + text(t('receipt.title').upcase, align: :center, style: :bold, size: 20) move_up 20 - text("#{t(:receipt_number)}: <b>#{id}</b>", inline_format: true) + text("#{t('receipt.number')}: <b>#{id}</b>", inline_format: true) move_up 15 - text("#{t(:amount)}: <b>#{formated_amount}</b>", + text("#{t('receipt.amount')}: <b>#{formated_amount}</b>", inline_format: true, align: :right) pad(10) { stroke_horizontal_rule } end end def body text( [ - "#{t(:received_from)} <b>#{payer}</b>", - "#{t(:the_amount_of)} <b>#{formated_amount}</b>", - "#{t(:relating_to)} <b>#{description}</b>." + "#{t('receipt.received_from')} <b>#{payer}</b>", + "#{t('receipt.the_amount_of')} <b>#{formated_amount}</b>", + "#{t('receipt.relating_to')} <b>#{description}</b>." ].join(' '), inline_format: true ) end @@ -188,11 +192,12 @@ load_translations set_locale end def load_translations - I18n.load_path += Dir[File.expand_path('config/locale/*.yml')] + locales = Dir[File.expand_path('../../../config/locale/*.yml', __FILE__)] + I18n.load_path += locales I18n.backend.load_translations end def set_locale I18n.locale = (locale || I18n.default_locale) @@ -203,10 +208,10 @@ end def tempfilepath @tempfilepath ||= File.join( Dir.tmpdir, - Dir::Tmpname.make_tmpname("#{t(:receipt)}", "#{id}.pdf") + Dir::Tmpname.make_tmpname("#{t('receipt.title')}", "#{id}.pdf") ) end end end