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