Skip to content

Commit

Permalink
feat: instantiate i18n as instance
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasename committed Mar 17, 2023
1 parent eee0cdb commit c767184
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 7 deletions.
16 changes: 10 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const cors = require('cors');
const routes = require('./routes');
const hbs = require('express-handlebars');
const bodyParser = require('body-parser');
const i18n = require('i18n');
// const i18n = require('i18n');
const { I18n } = require('i18n');

const app = express();
// Configuration //
Expand All @@ -15,14 +16,17 @@ const app = express();
app.use(session({
secret: 'Py0Bf3aWZC8kYkYTpRztmYMyS22pFFGi'
}));
i18n.configure({

// Internationalization //
const i18n = new I18n({
locales:['en-US'], //include langs
directory: __dirname + '/locales', //the path to the json file
defaultLocale: 'en-US' //default lang
directory: path.join(__dirname, 'locales'),
defaultLocale: 'en-US'
});
app.use(i18n.init);

// View engine //
hbsInstance = hbs.create({
const hbsInstance = hbs.create({
defaultLayout: 'main',
partialsDir: ['views/partials/'],
layoutsDir: 'views/layouts/',
Expand Down Expand Up @@ -77,7 +81,7 @@ function setLocale(req, res, next){
locale = req.acceptsLanguages();
}
// When there is no language preference, the language used on the website is English
else{
else {
locale = 'en-US';
}
// If the language preference saved in the cookie is different from the language preference used here, update the language preference setting in the cookie
Expand Down
Loading

0 comments on commit c767184

Please sign in to comment.