ReferenceError: t is not defined

I have this code index.coffee on my express.js / blade.js template using the i18next library

express = require "express"
gzippo = require "gzippo"
assets = require "connect-assets"
jsPaths = require "connect-assets-jspaths"
#stylus = require "stylus"
blade = require "blade"
i18n = require "i18next"
http = require "http"
https = require "https"
fs = require "fs"
json = ""

#### Application initialization
# Create app instance.
app = express()

# Define Port
app.port = process.env.PORT or process.env.VMC_APP_PORT or process.env.VCAP_APP_PORT or 3000


# Config module exports has `setEnvironment` function that sets app settings depending on environment.
config = require "./config"
app.configure "production", "development", "testing", ->
  config.setEnvironment app.settings.env


# i18next init
i18n.init
  detectLngQS: "lang"
  ,ns: { namespaces: ['ns.common', 'ns.layout'], defaultNs: 'ns.common'}
  ,resSetPath: "./locales/__lng__/new.__ns__.json"
  ,ignoreRoutes: ["images/", "public/", "css/", "js/"]
  #,locales:['de', 'en', 'fr', 'pt']
  ,extension:".json"
  #,saveMissing: true
  #,sendMissingTo: 'all'
  ,debug: true


#### View initialization 
# Add Connect Assets.
app.use assets(build : true)
jsPaths assets, console.log
#app.use i18n.init
# Set the public folder as static assets.
app.use gzippo.staticGzip(process.cwd() + "/assets")
app.use gzippo.staticGzip(process.cwd() + "/public")
app.use express.favicon(process.cwd() + "/images/favicon.ico")
app.use express.logger('dev')
# Set the nowjs folder as static assets and locales for i18next
app.use gzippo.staticGzip(process.cwd() + "/nowjs")
app.use gzippo.staticGzip(process.cwd() + "/locales")
app.use gzippo.staticGzip(process.cwd() + "/data/topo")
app.use (req, res, next) ->
  res.render '404',
    status: 404, url: req.url

# Set Blade View Engine and tell Express where our views are stored
app.set "view engine", "blade"
app.set "views", process.cwd() + "/views"


try
  app.set "chapters", require(process.cwd() + "/data/chapters.json")
  app.set "languages", require(process.cwd() + "/locales/config.json")
  app.set "translation", require(process.cwd() + "/locales/dev/translation.json")
catch e
  console.warn "files not found: " + e
  app.set "chapters", []
  app.set "languages", []
  app.set "translation", []
  next()
  return

# [Body parser middleware](http://www.senchalabs.org/connect/middleware-bodyParser.html) parses JSON or XML bodies into `req.body` object
app.use express.bodyParser()

app.use i18n.handle
app.use blade.middleware(process.cwd() + "/views")
app.use app.router

#### Finalization
# Register i18next AppHelper so we can use the translate function in template
i18n.registerAppHelper(app)

# Initialize routes
routes = require "./routes"
app.locals.pretty=true
routes(app)

# Export application object
module.exports = app

and my head.blade template is like:

header
    .navbar.navbar-inverse.navbar-fixed-top
        .navbar-inner
            button.btn.btn-navbar.collapsed(type="button" data-toggle="collapse" data-target="#navbar-nav-collapse")
                span.icon-bar
                span.icon-bar
                span.icon-bar
            a(href="/" class="brand")
                img(src="/images/tzm-logo-32.png")
                //span(class="tzm-i18n")=t("tzm")
            #navbar-nav-collapse.nav-collapse.collapse
                ul.nav
                    - var menu = locals.settings.translation.menu
                    - for(var i in menu)
                        - if (i === 'projects')
                            // FIXME class active does not toggle
                            li
                                a(href=""+i class=""+i data-i18n="menu."+i)!=t("ns.layout:menu."+i)

the error i get is when i load the site is:

☺  cake dev
Watching coffee files
Watching js files and running server


DEBUG: Running node-supervisor with
DEBUG:   program 'server'
DEBUG:   --watch '.app,views'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'js|blade'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node server'
DEBUG: Watching directory '/Users/khinester/Documents/Tutorials/Node/Blade/.app' for changes.
DEBUG: Watching directory '/Users/khinester/Documents/Tutorials/Node/Blade/views' for changes.
02:17:59 - compiled src/routes.coffee
02:17:59 - compiled src/index.coffee
02:17:59 - compiled src/social.coffee
02:17:59 - compiled src/config/index.coffee
02:17:59 - compiled src/controllers/guide.coffee
02:17:59 - compiled src/controllers/index.coffee
02:17:59 - compiled src/controllers/map.coffee
DEBUG: crashing child
DEBUG: Starting child process with 'node server'
set app environment: development
currentLng set to: dev
Assetizing map
Assetizing utils
SockJS v0.3.1 bound to "/_nowjs"
Server running at http://127.0.0.1: 9080
Press CTRL-C to stop server.
loaded file: locales/dev/ns.common.json
loaded file: locales/dev/ns.layout.json
ReferenceError: t is not defined
    at /Users/khinester/Documents/Tutorials/Node/Blade/views/header.blade:18:33

my error comes at t("ns.layout:menu."+i) i am initializing i18next but can't see why in this index.coffee it is not working!

any advice much appreciated

It is not because of i18next, t is missing in your code. When you do

- var foo = 'bar'
= foo
h1= foo

You get

bar<h1>bar</h1>

So

a(href=""+i class=""+i data-i18n="menu."+i)!=t("ns.layout:menu."+i)

translates to

a<href=""+i class=""+i data-i18n="menu."+i> ##Content from t##</a>

But t is not defined in your header.blade. So it shows that error.

it seems the order is not set correctly, as if i place it after app.use i18n.handle i18next t function is then available to the express application.

app.use (req, res, next) ->
  #the status option, or res.statusCode = 404
  #are equivalent, however with the option we
  #get the "status" local available as well
  res.render '404',
    status: 404, url: req.url