@igea/oac_frontend 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igea/oac_frontend",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Frontend service for the OAC project",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@
23
23
  "axios": "1.10.0",
24
24
  "express": "5.1.0",
25
25
  "get-port": "7.1.0",
26
+ "i18n": "^0.15.1",
26
27
  "twig": "1.17.1"
27
28
  },
28
29
  "devDependencies": {
package/src/index.js CHANGED
@@ -3,17 +3,38 @@ const express = require("express");
3
3
  const axios = require("axios");
4
4
  const getPort = require('get-port');
5
5
  const path = require("path");
6
+ const i18n = require('i18n');
7
+
8
+
9
+ i18n.configure({
10
+ locales: ['en', 'it'],
11
+ defaultLocale: 'it',
12
+ directory: path.join(__dirname, 'locales'),
13
+ queryParameter: 'lang',
14
+ autoReload: true,
15
+ updateFiles: false, // don't auto-create keys
16
+ api: {
17
+ '__': 't'
18
+ }
19
+ });
20
+
6
21
  const serviceName = "frontend"
7
22
 
8
23
  const app = express();
9
24
  let newPort = null
10
25
 
26
+ app.use(i18n.init);
11
27
  app.use(`/${serviceName}`, express.static(path.join(__dirname, 'public')));
12
28
  app.use(express.json());
13
29
 
14
30
  app.set('view engine', 'twig');
15
31
  app.set('views', path.join(__dirname, 'views'));
16
32
 
33
+ app.use((req, res, next) => {
34
+ res.locals.t = req.t;
35
+ next();
36
+ });
37
+
17
38
  const register = async function(){
18
39
  try {
19
40
  console.log(`Registering ${serviceName}...`);
@@ -0,0 +1,3 @@
1
+ {
2
+ "welcome": "Welcome"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "welcome": "Benvenuto"
3
+ }
@@ -6,5 +6,6 @@
6
6
  </head>
7
7
  <body>
8
8
  <h1>{{ message }}</h1>
9
+ <h2>{{ t('welcome') }}</h2>
9
10
  </body>
10
11
  </html>