Files
habitica/common/script/i18n.coffee
GihHubSphinx 232888212a Rewording translation string error message
Making error message about inaccurate translation match the UI link to
Report a Bug.

Addressing https://github.com/HabitRPG/habitrpg/issues/5405 to m
2015-06-15 01:42:47 +05:00

45 lines
1.4 KiB
CoffeeScript

_ = require 'lodash'
module.exports =
strings: null, # Strings for one single language
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]
locale = 'en' if (!locale? or (!module.exports.strings and !module.exports.translations[locale]))
if module.exports.strings
string = module.exports.strings[stringName]
else
string =
module.exports.translations[locale] and
module.exports.translations[locale][stringName]
clonedVars = _.clone(vars) or {}
clonedVars.locale = locale
if string
try
_.template(string, (clonedVars))
catch e
'Error processing the string. Please see Help > Report a Bug.'
else
if module.exports.strings
stringNotFound = module.exports.strings.stringNotFound
else if module.exports.translations[locale]
stringNotFound =
module.exports.translations[locale] and
module.exports.translations[locale].stringNotFound
try
_.template(stringNotFound, {string: stringName})
catch e
'Error processing the string. Please see Help > Report a Bug.'