From ce17bf33e04f25c4143ec166d3f6b7039e6d90d3 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 8 Jan 2014 13:39:49 +0100 Subject: [PATCH] complete and improve receive i18n --- app/controllers/orders_controller.rb | 14 +++++++++----- app/helpers/orders_helper.rb | 6 +++--- config/locales/en.yml | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 23788f86..e32f8f1d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -111,7 +111,8 @@ class OrdersController < ApplicationController unless request.post? @order_articles = @order.order_articles.ordered.includes(:article) else - flash[:notice] = "Order received: " + update_order_amounts + s = update_order_amounts + flash[:notice] = (s ? I18n.t('orders.receive.notice', :msg => s) : I18n.t('orders.receive.notice_none')) redirect_to @order end end @@ -156,6 +157,7 @@ class OrdersController < ApplicationController end def update_order_amounts + return if not params[:order_articles] # where to leave remainder during redistribution rest_to = [] rest_to << :tolerance if params[:rest_to_tolerance] @@ -183,10 +185,12 @@ class OrdersController < ApplicationController end end end - notice = " #{counts.shift} articles (#{cunits.shift} units) updated" - notice += ", #{counts.shift} (#{cunits.shift}) using tolerance" if params[:rest_to_tolerance] - notice += ", #{counts.shift} (#{cunits.shift}) go to stock if foodsoft would support that" if params[:rest_to_stock] - notice += ", #{counts.shift} (#{cunits.shift}) left over" + notice = I18n.t('orders.update_order_amounts.msg1', count: counts.shift, units: cunits.shift) + notice += ", " + I18n.t('orders.update_order_amounts.msg2', count: counts.shift, units: cunits.shift) if params[:rest_to_tolerance] + notice += ", " + I18n.t('orders.update_order_amounts.msg3', count: counts.shift, units: cunits.shift) if params[:rest_to_stock] + if counts[0]>0 or cunits[0]>0 + notice += ", " + I18n.t('orders.update_order_amounts.msg4', count: counts.shift, units: cunits.shift) + end end end diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 4c1e2367..e81576a9 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -20,9 +20,9 @@ module OrdersHelper if order_article.order.open? nil else - units_info = "#{order_article.units_to_order} #{heading_helper OrderArticle, :units_to_order}" - units_info += ", #{order_article.units_billed} #{heading_helper OrderArticle, :units_billed}" unless order_article.units_billed.nil? - units_info += ", #{order_article.units_received} #{heading_helper OrderArticle, :units_received}" unless order_article.units_received.nil? + units_info = "#{order_article.units_to_order} #{OrderArticle.human_attribute_name :units_to_order, count: order_article.units_to_order}" + units_info += ", #{order_article.units_billed} #{OrderArticle.human_attribute_name :units_billed_short, count: order_article.units_billed}" unless order_article.units_billed.nil? + units_info += ", #{order_article.units_received} #{OrderArticle.human_attribute_name :units_received_short, count: order_article.units_received}" unless order_article.units_received.nil? end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bfb46a2..31c7d47c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -80,13 +80,19 @@ en: supplier: Supplier order_article: article: Article - missing_units: Missing units + missing_units: + one: Missing unit + other: Missing units missing_units_short: Missing quantity: Desired amount quantity_short: Desired - units_received: Received units + units_received: + one: Received unit + other: Received units units_received_short: Received - units_to_order: Ordered units + units_to_order: + one: Ordered unit + other: Ordered units units_to_order_short: Ordered update_current_price: Globally update current price order_comment: @@ -1149,6 +1155,8 @@ en: receive: add_article: Add article consider_member_tolerance: consider tolerance + notice: ! 'Order received: %{msg}' + notice_none: No new articles to receive rest_to_stock: rest to stock submit: Receive order surplus_options: 'Distribution options:' @@ -1184,6 +1192,11 @@ en: open: open update: notice: The order was updated. + update_order_amounts: + msg1: "%{count} articles (%{units} units) updated" + msg2: "%{count} (%{units}) using tolerance" + msg3: "%{count} (%{units}) go to stock if foodsoft would support that [don't translate]" + msg4: "%{count} (%{units}) left over" pages: all: new_page: Create new page