mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
- 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
18 lines
524 B
CoffeeScript
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
|