From 4ca48511ba4d1be35b8b24983e4d3bb7481bbbd0 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 9 Nov 2011 18:31:23 +0100 Subject: [PATCH] Added dutch i18n for invoice generation (controller, template). --- locale/nl.yml | 131 ++++++++++++++++++++++++++++++++++++++ stoptime.rb | 13 +++- templates/invoice.tex.erb | 16 ++--- 3 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 locale/nl.yml diff --git a/locale/nl.yml b/locale/nl.yml new file mode 100644 index 0000000..ea0846f --- /dev/null +++ b/locale/nl.yml @@ -0,0 +1,131 @@ +nl: + date: + formats: + default: "%Y-%m-%d" + short: "%b %d" + long: "%d %B %Y" + month_and_year: "%B %Y" + + day_names: [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag] + abbr_day_names: [zon, maa, din, woe, don, vrij, zat] + + # Don't forget the nil at the beginning; there's no such thing as a 0th month + month_names: [~, januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november, december] + abbr_month_names: [~, jan, feb, mar, apr, mei, jun, jul, aug, sep, okt, nov, dec] + order: + - :year + - :month + - :day + + time: + formats: + default: "%a %d %b %Y %H:%M:%S %z" + short: "%d %b %H:%M" + long: "%d %B %Y %H:%M" + date_only: "%Y-%m-%d" + month_and_year: "%B %Y" + am: "am" + pm: "pm" + +# Used in array.to_sentence. + support: + array: + words_connector: ", " + two_words_connector: " en " + last_word_connector: " en " + + number: + format: + separator: "," + delimiter: "." + precision: 2 + significant: false + strip_insignificant_zeros: false + + currency: + format: + format: "%u%n" + unit: "€" + separator: "," + delimiter: "." + precision: 2 + significant: false + strip_insignificant_zeros: false + + percentage: + format: + delimiter: "" + + precision: + format: + delimiter: "" + + human: + format: + delimiter: "" + precision: 3 + significant: true + strip_insignificant_zeros: true + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" + decimal_units: + format: "%n %u" + units: + unit: "" + thousand: duizend + million: millioen + billion: miljard + trillion: biljoen + quadrillion: biljard + + datetime: + distance_in_words: + half_a_minute: "een halve minuut" + less_than_x_seconds: + one: "minder dan 1 seconde" + other: "minder dan %{count} seconden" + x_seconds: + one: "1 seconde" + other: "%{count} seconden" + less_than_x_minutes: + one: "minder dan 1 minuut" + other: "minder dan %{count} minuten" + x_minutes: + one: "1 minuut" + other: "%{count} minuten" + about_x_hours: + one: "ongeveer 1 uur" + other: "ongeveer %{count} uren" + x_days: + one: "1 dag" + other: "%{count} dagen" + about_x_months: + one: "ongeveer 1 maand" + other: "ongeveer %{count} maanden" + x_months: + one: "1 maand" + other: "%{count} maanden" + about_x_years: + one: "ongeveer 1 jaar" + other: "ongeveer %{count} jaren" + over_x_years: + one: "maar dan 1 jaarj" + other: "meer dan %{count} jaren" + almost_x_years: + one: "bijna 1 jaar" + other: "bijna %{count} jaren" + prompts: + year: "Jaar" + month: "Maand" + day: "Dag" + hour: "Uur" + minute: "Minuut" + second: "Seconden" diff --git a/stoptime.rb b/stoptime.rb index 1b58a07..e234b50 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -10,6 +10,7 @@ # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. +require "action_view" require "active_support" require "camping" require "markaby" @@ -23,6 +24,9 @@ unless defined? PUBLIC_DIR PUBLIC_DIR = Pathname.new(__FILE__).dirname.expand_path + "public" TEMPLATE_DIR = Pathname.new(__FILE__).dirname.expand_path + "templates" + # Set up the locales. + I18n.load_path += Dir[ File.join('locale', '*.yml') ] + # Set the default date(/time) format. ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( :default => "%Y-%m-%d %H:%M", @@ -493,6 +497,9 @@ module StopTime::Controllers end class CustomersNInvoicesX + include ActionView::Helpers::NumberHelper + include I18n + def get(customer_id, invoice_number) # FIXME: make this (much) nicer! if m = invoice_number.match(/(\d+)\.(\w+)$/) @@ -535,8 +542,10 @@ module StopTime::Controllers template = TEMPLATE_DIR + "invoice.tex.erb" tex_file = PUBLIC_DIR + "#{number}.tex" - erb = ERB.new(File.read(template)) - File.open(tex_file, "w") { |f| f.write(erb.result(binding)) } + with_locale :nl do + erb = ERB.new(File.read(template)) + File.open(tex_file, "w") { |f| f.write(erb.result(binding)) } + end end def _generate_invoice_pdf(number) diff --git a/templates/invoice.tex.erb b/templates/invoice.tex.erb index ab78297..15279a3 100644 --- a/templates/invoice.tex.erb +++ b/templates/invoice.tex.erb @@ -42,9 +42,9 @@ to={<%= @customer.name %>\\<%= @customer.address_street%>\\ <%= @customer.address_postal_code %> <%= @customer.address_city %>}, % Headlines. - date=<%= @invoice.updated_at.to_formatted_s(:day_code) %>, + date=<%= @invoice.created_at.to_formatted_s(:day_code) %>, ourref=<%= @number %>, -<% period = @period.map { |m| m.to_formatted_s(:month_and_year) }.uniq +<% period = @period.map { |p| I18n.l p, :format => :month_and_year }.uniq case period.length when 1 %> subject=Factuur <%= period.first %>,<% when 2 %> subject=Factuur <%= period.join(" t/m ") %>,<% @@ -93,11 +93,11 @@ @tasks.each do |task, line| if line[0].nil? and line[1].nil? %> \ifcitem{<%= task %>}% - {<%= "%.2f" % line[2] %>}<% + {<%= number_with_precision(line[2]) %>}<% else %> \ihitem{<%= task %>}% - {<%= "%.2f" % line[0] %>}{<%= "%.2f" % line[1] %>}% - {<%= "%.2f" % line[2] %>}<% + {<%= number_with_precision(line[0]) %>}{<%= number_with_precision(line[1]) %>}% + {<%= number_with_precision(line[2]) %>}<% end subtotal += line[2] end @@ -106,10 +106,10 @@ \ihnosubtotal{} <% else vat = subtotal * VATRate/100 %> - \ihsubtotal{<%= "%.2f" % subtotal %>} - \ihvat{<%= "%.2f" % vat %>} <% + \ihsubtotal{<%= number_with_precision(subtotal) %>} + \ihvat{<%= number_with_precision(vat) %>}<% end %> - \ihtotal{<%= "%.2f" % (subtotal + vat) %>} + \ihtotal{<%= number_with_precision(subtotal + vat) %>} \end{ihtable} \vspace{2em}