Files
openfoodnetwork/app/assets/javascripts/darkswarm/i18n.translate.js.coffee
Maikel Linke d925c2aefc 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
2016-03-09 14:29:54 +11:00

18 lines
524 B
CoffeeScript

# Declares the translation function t.
# You can use translate('login') or t('login') in Javascript.
window.translate = (key, options = {}) ->
unless 'I18n' of window
console.log 'The I18n object is undefined. Cannot translate text.'
return 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
window.t = window.translate