mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
better testing of existence of I18n
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
# Declares the translation function t.
|
||||
# You can use t('login') in Javascript.
|
||||
window.t = (key, options = {}) ->
|
||||
if I18n == undefined
|
||||
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]
|
||||
return key if text == undefined
|
||||
text = text.split("%{#{name}}").join(value) for name, value of options
|
||||
for name, value of options
|
||||
text = text.split("%{#{name}}").join(value)
|
||||
text
|
||||
|
||||
# Provides the translation function t on all scopes.
|
||||
|
||||
Reference in New Issue
Block a user