Skip to content

Commit

Permalink
new try with readonly i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
hsc-nue committed Sep 21, 2023
1 parent c19ac5d commit 0cba25e
Show file tree
Hide file tree
Showing 9 changed files with 1,092 additions and 1,886 deletions.
14 changes: 14 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import nodemailer from "nodemailer";
const bodyParser = require("body-parser");
import jwt from "jsonwebtoken";
var QRCode = require("qrcode");
const { I18n } = require("i18n");
const path = require("path");

// we must ensure that no write access to the file system is needed; as we are running on a readonly serverless platform
const i18n = new I18n({
locales: ["en", "de"], // other locales will fallback to en silently
fallbacks: { "de-*": "de" },
retryInDefaultLocale: true,
updateFiles: false, // I hope to avoid write access to the file system
queryParameter: 'lang',
directory: path.join(__dirname, "locales"),
});
console.log("__dirname: ", __dirname);

const app = express();

Expand All @@ -23,6 +36,7 @@ app.use(express.static("public"));
app.use(express.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(i18n.init); // default: using 'accept-language' header to guess language settings

// view engine
app.set("view engine", "ejs");
Expand Down
13 changes: 13 additions & 0 deletions dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ require("dotenv").config();
const bodyParser = require("body-parser");
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
var QRCode = require("qrcode");
const { I18n } = require("i18n");
const path = require("path");
// we must ensure that no write access to the file system is needed; as we are running on a readonly serverless platform
const i18n = new I18n({
locales: ["en", "de"],
fallbacks: { "de-*": "de" },
retryInDefaultLocale: true,
updateFiles: false,
queryParameter: 'lang',
directory: path.join(__dirname, "locales"),
});
console.log("__dirname: ", __dirname);
const app = express();
// middleware
app.use(express.static("public"));
app.use(express.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(i18n.init); // default: using 'accept-language' header to guess language settings
// view engine
app.set("view engine", "ejs");
// database connection
Expand Down
12 changes: 12 additions & 0 deletions dist/locales/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"appName": "HSC Leihnoten Verwaltung",
"Ausleihen anzeigen": "Ausleihen anzeigen",
"QRCode für Login anzeigen": "QRCode für Login anzeigen",
"Noten": "Noten",
"Leihnoten registrieren": "Leihnoten registrieren",
"Noten Ausleihe": "Noten Ausleihe",
"Noten Rückgabe": "Noten Rückgabe",
"Benutzer": "Benutzer",
"Benutzer anlegen": "Benutzer anlegen",
"Benutzer Liste": "Benutzer Liste"
}
12 changes: 12 additions & 0 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"appName": "HSC rental score management",
"Noten": "Scores",
"Leihnoten registrieren": "Register rental scores",
"Noten Ausleihe": "Checkout score",
"Noten Rückgabe": "Return score",
"Ausleihen anzeigen": "Show checkouts",
"Benutzer": "User",
"Benutzer anlegen": "Register user",
"Benutzer Liste": "User list",
"QRCode für Login anzeigen": "Show QR code for login"
}
12 changes: 12 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"appName": "HSC Leihnoten Verwaltung",
"Ausleihen anzeigen": "Ausleihen anzeigen",
"QRCode für Login anzeigen": "QRCode für Login anzeigen",
"Noten": "Noten",
"Leihnoten registrieren": "Leihnoten registrieren",
"Noten Ausleihe": "Noten Ausleihe",
"Noten Rückgabe": "Noten Rückgabe",
"Benutzer": "Benutzer",
"Benutzer anlegen": "Benutzer anlegen",
"Benutzer Liste": "Benutzer Liste"
}
12 changes: 12 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"appName": "HSC rental score management",
"Noten": "Scores",
"Leihnoten registrieren": "Register rental scores",
"Noten Ausleihe": "Checkout score",
"Noten Rückgabe": "Return score",
"Ausleihen anzeigen": "Show checkouts",
"Benutzer": "User",
"Benutzer anlegen": "Register user",
"Benutzer Liste": "User list",
"QRCode für Login anzeigen": "Show QR code for login"
}
Loading

0 comments on commit 0cba25e

Please sign in to comment.