mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Translate Spree payment, shipment and order states
- Copied translations for payment_states, shipment_states and order_states into locale en.yml. - Enabled global Javascript function `translate` to deal with scopes like 'spree.shipment_states'. - Removed `humanize` call from order serializer and added translation scopes to accounts page. - Test OrderSerializer for untranslated attributes - Require spec helper in serializer specs
This commit is contained in:
@@ -4,8 +4,13 @@ window.translate = (key, options = {}) ->
|
||||
unless 'I18n' of window
|
||||
console.log 'The I18n object is undefined. Cannot translate text.'
|
||||
return key
|
||||
return key unless key of I18n
|
||||
text = I18n[key]
|
||||
dict = I18n
|
||||
parts = key.split '.'
|
||||
while (parts.length)
|
||||
part = parts.shift()
|
||||
return key unless part of dict
|
||||
dict = dict[part]
|
||||
text = dict
|
||||
for name, value of options
|
||||
text = text.split("%{#{name}}").join(value)
|
||||
text
|
||||
|
||||
@@ -5,7 +5,7 @@ module Api
|
||||
has_many :payments, serializer: Api::PaymentSerializer
|
||||
|
||||
def completed_at
|
||||
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: :long) #.to_formatted_s(:long_ordinal)
|
||||
object.completed_at.blank? ? "" : I18n.l(object.completed_at, format: :long)
|
||||
end
|
||||
|
||||
def total
|
||||
@@ -13,15 +13,15 @@ module Api
|
||||
end
|
||||
|
||||
def shipment_state
|
||||
object.shipment_state ? object.shipment_state.humanize : nil # Or a call to t() here?
|
||||
object.shipment_state ? object.shipment_state : nil
|
||||
end
|
||||
|
||||
def payment_state
|
||||
object.payment_state ? object.payment_state.humanize : nil # Or a call to t() here?
|
||||
object.payment_state ? object.payment_state : nil
|
||||
end
|
||||
|
||||
def state
|
||||
object.state ? object.state.humanize : nil # Or a call to t() here?
|
||||
object.state ? object.state : nil
|
||||
end
|
||||
|
||||
def path
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
%td.order1
|
||||
%a{"bo-href" => "order.path", "bo-text" => "('order' | t )+ ' ' + order.number"}
|
||||
%td.order2{"bo-text" => "order.completed_at"}
|
||||
%td.order3.show-for-large-up{"bo-text" => "order.payment_state | t"}
|
||||
%td.order4.show-for-large-up{"bo-text" => "order.shipment_state | t"}
|
||||
%td.order3.show-for-large-up{"bo-text" => "'spree.payment_states.' + order.payment_state | t"}
|
||||
%td.order4.show-for-large-up{"bo-text" => "'spree.shipment_states.' + order.shipment_state | t"}
|
||||
%td.order5.text-right{"bo-text" => "order.total | localizeCurrency"}
|
||||
%td.order6.text-right.show-for-large-up{"ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}", "bo-text" => "order.outstanding_balance | localizeCurrency"}
|
||||
%td.order7.text-right{"ng-class" => "{'credit' : order.running_balance < 0, 'debit' : order.running_balance > 0, 'paid' : order.running_balance == 0}", "bo-text" => "order.running_balance | localizeCurrency"}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
%strong{"bo-text" => "distributor.name"}
|
||||
.columns.small-8.small-offset-2.medium-3.text-right
|
||||
%span.margin-top.distributor-balance{"bo-text" => "distributor.balance | formatBalance", "ng-class" => "{'credit' : distributor.balance < 0, 'debit' : distributor.balance > 0, 'paid' : distributor.balance == 0}" }
|
||||
-# %span.margin-top{"bo-text" => "('balance' | t) + ': ' + Orders.currency_symbol + distributor.balance", "ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}"}
|
||||
.columns.small-2.medium-2.text-right
|
||||
%span.margin-top
|
||||
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}
|
||||
|
||||
@@ -689,3 +689,34 @@ Please follow the instructions there to make your enterprise visible on the Open
|
||||
you_have_no_orders_yet: "You have no orders yet"
|
||||
running_balance: "Running balance"
|
||||
outstanding_balance: "Outstanding balance"
|
||||
|
||||
spree:
|
||||
shipment_states:
|
||||
backorder: backorder
|
||||
partial: partial
|
||||
pending: pending
|
||||
ready: ready
|
||||
shipped: shipped
|
||||
payment_states:
|
||||
balance_due: balance due
|
||||
completed: completed
|
||||
checkout: checkout
|
||||
credit_owed: credit owed
|
||||
failed: failed
|
||||
paid: paid
|
||||
pending: pending
|
||||
processing: processing
|
||||
void: void
|
||||
order_state:
|
||||
address: address
|
||||
adjustments: adjustments
|
||||
awaiting_return: awaiting return
|
||||
canceled: canceled
|
||||
cart: cart
|
||||
complete: complete
|
||||
confirm: confirm
|
||||
delivery: delivery
|
||||
payment: payment
|
||||
resumed: resumed
|
||||
returned: returned
|
||||
skrill: skrill
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#require 'spec_helper'
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::EnterpriseSerializer do
|
||||
let(:serializer) { Api::EnterpriseSerializer.new enterprise, data: data }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#require 'spec_helper'
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::OrderSerializer do
|
||||
let(:serializer) { Api::OrderSerializer.new order }
|
||||
@@ -9,9 +9,9 @@ describe Api::OrderSerializer do
|
||||
expect(serializer.to_json).to match order.number.to_s
|
||||
end
|
||||
|
||||
it "convert the state attributes to readable strings" do
|
||||
expect(serializer.to_json).to match "Complete"
|
||||
expect(serializer.to_json).to match "Balance due"
|
||||
it "convert the state attributes to translatable keys" do
|
||||
expect(serializer.to_json).to match "complete"
|
||||
expect(serializer.to_json).to match "balance_due"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#require 'spec_helper'
|
||||
require 'spec_helper'
|
||||
|
||||
describe Api::OrdersByDistributorSerializer do
|
||||
|
||||
|
||||
Reference in New Issue
Block a user