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 protect_from_forgery
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
after_filter :remove_controller after_filter :remove_controller
around_filter :set_time_zone around_filter :set_time_zone, :set_currency
# Returns the controller handling the current request. # Returns the controller handling the current request.
@ -180,4 +180,16 @@ class ApplicationController < ActionController::Base
Time.zone = old_time_zone Time.zone = old_time_zone
end 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 end

View file

@ -2,3 +2,8 @@
collection: I18n.available_locales.map {|l| [t("simple_form.options.settings.profile.language.#{l}"), l]} 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, :ignore_browser_locale, as: :boolean
= config_input form, :time_zone, as: :time_zone, include_blank: true, input_html: {class: 'input-xlarge'} = 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 #ignore_browser_locale: false
# Default timezone, e.g. UTC, Amsterdam, Berlin, etc. # Default timezone, e.g. UTC, Amsterdam, Berlin, etc.
#time_zone: Berlin #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 in percent
price_markup: 2.0 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: contact:
email: General contact email address, shown on website as well as some forms. 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. 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. homepage: Website of your foodcoop.
help_url: Documentation website. help_url: Documentation website.
applepear_url: Website where the apple and pear system for tasks is explained. applepear_url: Website where the apple and pear system for tasks is explained.
@ -481,6 +483,8 @@ en:
country: Country country: Country
email: Email email: Email
phone: Phone phone: Phone
currency_unit: Currency
currency_space: add space
homepage: Homepage homepage: Homepage
help_url: Documentation URL help_url: Documentation URL
applepear_url: Apple system URL applepear_url: Apple system URL

View file

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