Den Delimarsky Den Delimarsky - 4 months ago 12x
Node.js Question

Handlebars - Access Navigator

I am modifying parts of the Ghost blog to use different languages. For that, I am writing a Handlebars helper:

hbs.registerHelper("language", function () {
var lang = (navigator.language) ? navigator.language : navigator.userLanguage;
return lang;

However, I get an error where the message is
navigator is undefined
. Ghost is using
, so I am guessing it has something to do with the custom flavor, because the same helper was declared here.

What obvious thing am I missing here?


I figured this out after a late night of coding.

In index.js, within the renderPost function, I can (in a very primitive way) query the client language: = req.headers["accept-language"].substring(0,5).toLowerCase();

This will create a new property within the post object. With the help of a custom conditional helper (placed in helpers.js):

{{#ifCond language '==' 'en-us'}}
     {{content lang="1"}}
     {{content lang="2"}}

In core\server\helpers\content.js I've already implemented a custom language parser that displays the right content depending on the index.