-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (26 loc) · 911 Bytes
/
Copy pathapp.js
File metadata and controls
32 lines (26 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var express = require('express');
var path = require('path');
var i18n = require('i18next');
var i18nFsBackend = require('i18next-node-fs-backend');
var i18nMiddleware = require('i18next-express-middleware');
var app = express();
// i18next 初始設定
i18n.use(i18nMiddleware.LanguageDetector) // 自動偵測用戶端語系
.use(i18nFsBackend)
.init({
fallbackLng: "en", // 備用語系,擷取失敗時會使用到這裡
backend: {
loadPath: "locales/{{lng}}/translation.json",
}
});
app.use(i18nMiddleware.handle(i18n, {
}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.get("/", function(req, res) {
console.log('用戶端語系:' + req.language);
res.render('index');
})
app.listen(3000, function() {
console.log("HTTP 伺服器在 http://127.0.0.1:3000/ 上運行");
})