allow to configure currency (closes foodcoops#258)

This commit is contained in:
wvengen 2014-06-27 11:45:34 +02:00
parent f09ef892dc
commit 68ccc19c70
6 changed files with 34 additions and 1 deletions

View file

@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
after_filter :remove_controller
around_filter :set_time_zone
around_filter :set_time_zone, :set_currency
# Returns the controller handling the current request.
@ -180,4 +180,16 @@ class ApplicationController < ActionController::Base
Time.zone = old_time_zone
end
# Set currency according to foodcoop preference.
# @see #set_time_zone
def set_currency
old_currency = ::I18n.t('number.currency.format.unit')
new_currency = FoodsoftConfig[:currency_unit] || ''
new_currency += "\u202f" if FoodsoftConfig[:currency_space]
::I18n.backend.store_translations(::I18n.locale, number: {currency: {format: {unit: new_currency}}})
yield
ensure
::I18n.backend.store_translations(::I18n.locale, number: {currency: {format: {unit: old_currency}}})
end
end

View file

@ -2,3 +2,8 @@
collection: I18n.available_locales.map {|l| [t("simple_form.options.settings.profile.language.#{l}"), l]}
= config_input form, :ignore_browser_locale, as: :boolean
= config_input form, :time_zone, as: :time_zone, include_blank: true, input_html: {class: 'input-xlarge'}
= config_input form, :currency_unit do
= config_input_field form, :currency_unit, class: 'input-mini'
%label.inline
= config_input_label form, :currency_space
= config_input_field form, :currency_space, as: :boolean

View file

@ -39,6 +39,9 @@ default: &defaults
#ignore_browser_locale: false
# Default timezone, e.g. UTC, Amsterdam, Berlin, etc.
#time_zone: Berlin
# Currency symbol, and whether to add a whitespace after the unit.
#currency_unit: €
#currency_space: true
# price markup in percent
price_markup: 2.0

View file

@ -0,0 +1,7 @@
# remove all currency translations, so that we can set the default language and
# have it shown in all other languages too
::I18n.available_locales.each do |locale|
unless locale == ::I18n.default_locale
::I18n.backend.store_translations(locale, number: {currency: {format: {unit: nil}}})
end
end

View file

@ -450,6 +450,8 @@ en:
contact:
email: General contact email address, shown on website as well as some forms.
street: Address, typically this will be your delivery and pick-up location.
currency_unit: Currency symbol for displaying prices.
currency_space: Whether to add whitespace after the currency symbol.
homepage: Website of your foodcoop.
help_url: Documentation website.
applepear_url: Website where the apple and pear system for tasks is explained.
@ -481,6 +483,8 @@ en:
country: Country
email: Email
phone: Phone
currency_unit: Currency
currency_space: add space
homepage: Homepage
help_url: Documentation URL
applepear_url: Apple system URL

View file

@ -235,6 +235,8 @@ class FoodsoftConfig
use_apple_points: true,
# English is the default language, and this makes it show up as default.
default_locale: 'en',
currency_unit: '€',
currency_space: true,
foodsoft_url: 'https://github.com/foodcoops/foodsoft',
# The following keys cannot, by default, be set by foodcoops themselves.
protected: {