fix(i18n): fix /content api call

This commit is contained in:
Matteo Pagliazzi 2014-05-15 23:15:57 +02:00
parent eedb1d147c
commit 01c9307cd1
2 changed files with 13 additions and 1 deletions

View file

@ -17,7 +17,16 @@ var api = module.exports;
// api.purchase // Shared.ops
api.getContent = function(req, res, next) {
res.json(shared.content);
var language = req.query.language; //|| 'en' in i18n
var content = _.cloneDeep(shared.content);
var walk = function(obj){
_.each(obj, function(item, key, source){
if(_.isPlainObject(item) || _.isArray(item)) return walk(item);
if(_.isFunction(item) && item.i18nLangFunc) source[key] = item(language);
});
}
walk(content);
res.json(content);
}
/*

View file

@ -41,6 +41,9 @@ module.exports = (swagger, v2) ->
'/content':
spec:
description: "Get all available content objects. This is essential, since Habit often depends on item keys (eg, when purchasing a weapon)."
parameters: [
query("language","Optional language to use for content's strings. Default is english.","string")
]
action: user.getContent