Closed mikesparr closed 10 years ago
Hi Mike,
Thanks for the info.
I'm inclined to leave it as is; since the next version of Kraken (Which has a looot of internal refactoring) is just around the corner.
All these examples are being refactored to use it, and will be centralized within the Kraken repo.
At the very least, I will do a check to see if the context object is defined.
Thanks again!
Hi,
I found the issue was in the /lib/language.js
file that is added to middleware in the i18n example project. It assumes the cookie will always exist that set language and sets context. The other helper examples assume these will exist too. The solution for future examples (aside from checking for context in helpers) is to edit the language.js to the following and add fallbackLang just in case cookie doesn't yet exist or is cleared out.
'use strict';
var nconf = require('nconf');
module.exports = function () {
return function (req, res, next) {
//Pick up the language cookie.
var language = req.cookies.language;
//Set the locality for this response. The template will pick the appropriate bundle
if (language) {
res.locals.context = res.locals.context || {};
res.locals.context.locality = language;
} else {
// get language from config and set
var fallbackLang = nconf.get('i18n').fallback || 'en-US';
res.locals.context = res.locals.context || {};
res.locals.context.locality = fallbackLang.toLowerCase();
}
next();
};
};
I look forward to next version of KrakenJS and appreciate any insights into breaking changes to code, if applicable, because we're still in evaluation mode and prototyping.
Can others reproduce this issue?
My test setup (mainly w/ example apps from KrakenJS site):
What I did:
/lib/
and reference on dust templateError:
My temp fix (hack) I saw this with my other custom helpers and added the following:
I think this is a 'hack' solution, however, and doesn't solve issue that for some reason on browser cookie/cache/data clear it breaks context and dust not passing context to helpers. I'm on Mac OSX Mavericks w/ versions seen in stack dump above and another engineer was able to recreate the same issue on Chrome as I did on Firefox, Chrome, and Safari.
To get working I had to start app with fallbackLang and then leverage the i18n_Example /set-language and then I believe it populated the context and thereafter the tags don't appear to be failing.