node.js - ReferenceError: t is not defined -
i have code index.coffee on express.js / blade.js template using 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 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 public folder 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 nowjs folder static assets , locales 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 , tell express our views 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 `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 can use 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 head.blade template 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 in menu) - if (i === 'projects') // fixme class active not toggle li a(href=""+i class=""+i data-i18n="menu."+i)!=t("ns.layout:menu."+i)
the error when load site is:
☺ cake dev watching coffee files watching js files , running server debug: running node-supervisor debug: program 'server' debug: --watch '.app,views' debug: --ignore 'undefined' debug: --extensions 'js|blade' debug: --exec 'node' debug: starting child process 'node server' debug: watching directory '/users/khinester/documents/tutorials/node/blade/.app' changes. debug: watching directory '/users/khinester/documents/tutorials/node/blade/views' 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 'node server' set app environment: development currentlng set to: dev assetizing map assetizing utils sockjs v0.3.1 bound "/_nowjs" server running @ http://127.0.0.1: 9080 press ctrl-c stop server. loaded file: locales/dev/ns.common.json loaded file: locales/dev/ns.layout.json referenceerror: t not defined @ /users/khinester/documents/tutorials/node/blade/views/header.blade:18:33
my error comes @ t("ns.layout:menu."+i)
initializing i18next can't see why in index.coffee not working!
any advice appreciated
it not because of i18next, t missing in code. when
- var foo = 'bar' = foo h1= foo
you
bar<h1>bar</h1>
so
a(href=""+i class=""+i data-i18n="menu."+i)!=t("ns.layout:menu."+i)
translates
a<href=""+i class=""+i data-i18n="menu."+i> ##content t##</a>
but t not defined in header.blade. shows error.
Comments
Post a Comment