2014-03-05 14:48:31 +00:00
|
|
|
_ = require 'lodash'
|
|
|
|
|
|
|
|
|
|
module.exports =
|
2014-03-16 17:37:53 +00:00
|
|
|
strings: null, # Strings for one single language
|
2014-03-05 16:04:22 +00:00
|
|
|
translations: {} # Strings for multiple languages {en: strings, de: strings, ...}
|
|
|
|
|
t: (stringName) -> # Other parameters allowed are vars (Object) and locale (String)
|
|
|
|
|
vars = arguments[1]
|
|
|
|
|
|
|
|
|
|
if _.isString(arguments[1])
|
|
|
|
|
vars = null
|
|
|
|
|
locale = arguments[1]
|
|
|
|
|
else if arguments[2]?
|
|
|
|
|
vars = arguments[1]
|
|
|
|
|
locale = arguments[2]
|
|
|
|
|
|
2014-05-15 20:45:22 +00:00
|
|
|
locale = 'en' if (!locale? or (!module.exports.strings and !module.exports.translations[locale]))
|
|
|
|
|
string = if (!module.exports.strings) then module.exports.translations[locale][stringName] else module.exports.strings[stringName]
|
2014-03-05 14:48:31 +00:00
|
|
|
|
|
|
|
|
if string
|
2014-09-12 12:26:26 +00:00
|
|
|
try{
|
|
|
|
|
return _.template(string, (vars or {}))
|
|
|
|
|
}catch (e){
|
|
|
|
|
return 'Error processing string. Please report to http://github.com/HabitRPG/habitrpg.'
|
|
|
|
|
}
|
2014-03-05 14:48:31 +00:00
|
|
|
else
|
2014-05-15 20:45:22 +00:00
|
|
|
stringNotFound = if (!module.exports.strings) then module.exports.translations[locale].stringNotFound else module.exports.strings.stringNotFound
|
2014-09-12 12:26:26 +00:00
|
|
|
try{
|
|
|
|
|
return _.template(stringNotFound, {string: stringName})
|
|
|
|
|
}catch (e){
|
|
|
|
|
return 'Error processing string. Please report to http://github.com/HabitRPG/habitrpg.'
|
|
|
|
|
}
|