better testing of existence of I18n

This commit is contained in:
Maikel Linke
2015-10-01 14:16:59 +10:00
parent 6b1e66ed26
commit 0eed8b4578

View File

@@ -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.