improve(i18n): add locales for content.json, add code for server to i18n, build

This commit is contained in:
Matteo Pagliazzi
2014-03-05 17:04:22 +01:00
parent 7af95edc8c
commit 968c899836
12 changed files with 271 additions and 22 deletions
+15 -4
View File
@@ -1,11 +1,22 @@
_ = require 'lodash'
module.exports =
strings: {}
t: (stringName, vars) ->
string = module.exports.strings[stringName]
strings: {}, # 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]
string = if locale then module.exports.translations[locale][stringName] else module.exports.strings[stringName]
if string
if vars then _.template(string, vars) else string
else
_.template(module.exports.strings.stringNotFound, {string: stringName})
stringNotFound = if locale then module.exports.translations[locale].stringNotFound else module.exports.strings.stringNotFound
_.template(stringNotFound, {string: stringName})