Start simple translation approach
This commit is contained in:
46
index.js
46
index.js
@@ -65,13 +65,21 @@ DB.getDB.then((DB) => {
|
|||||||
|
|
||||||
// route for Home-Page
|
// route for Home-Page
|
||||||
app.get('/', sessionChecker, async (req, res) => {
|
app.get('/', sessionChecker, async (req, res) => {
|
||||||
if (req.userInfo) return res.json({
|
try {
|
||||||
status: "ok",
|
const userInfo = req.userInfo;
|
||||||
userInfo: req.userInfo,
|
if(!userInfo) {
|
||||||
profileInfo: req.profileInfo
|
// This should not happend, since the sessionChecker should redirect to login
|
||||||
});
|
return res.status(401).json({ status: "Unauthorized" });
|
||||||
// This should not happend, since the sessionChecker should redirect to login
|
}
|
||||||
res.json({ status: "ok" });
|
return res.json({
|
||||||
|
status: "ok",
|
||||||
|
userInfo: req.userInfo,
|
||||||
|
profileInfo: req.profileInfo
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error processing / path", error);
|
||||||
|
return res.status(500).json({ status: "Internal server error" });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for an invitation for an email
|
// Check for an invitation for an email
|
||||||
@@ -136,12 +144,24 @@ DB.getDB.then((DB) => {
|
|||||||
|
|
||||||
// This is the endpoint to refresh the push notification token
|
// This is the endpoint to refresh the push notification token
|
||||||
app.post('/token/', sessionChecker, async (req, res) => {
|
app.post('/token/', sessionChecker, async (req, res) => {
|
||||||
const profileid = getProfileId(req);
|
try {
|
||||||
let token = req.body.token
|
const profileid = getProfileId(req);
|
||||||
DB.setProfileToken(profileid, token);
|
const { token } = req.body;
|
||||||
return res.json({
|
// Validate token presence
|
||||||
status: "ok"
|
if (!token) {
|
||||||
});
|
return res.status(400).json({ status: 'Token is required' });
|
||||||
|
}
|
||||||
|
// Set the token in the database and wait for completion
|
||||||
|
const result = await DB.setProfileToken(profileid, token);
|
||||||
|
// Assuming DB.setProfileToken() could fail, handle it appropriately
|
||||||
|
if (!result) {
|
||||||
|
return res.status(500).json({ status: 'Failed to update token' });
|
||||||
|
}
|
||||||
|
return res.json({ status: 'ok' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting profile token:', error);
|
||||||
|
return res.status(500).json({ status: 'Internal server error' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Used for webpush notifications
|
// Used for webpush notifications
|
||||||
|
|||||||
5
translations/en.json
Normal file
5
translations/en.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"hello": "Hello",
|
||||||
|
"new_password": "This is your new password: {{password}}",
|
||||||
|
"login_link": "Log in here"
|
||||||
|
}
|
||||||
15
translations/translations.js
Normal file
15
translations/translations.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const loadTranslation = (languageCode) => {
|
||||||
|
try {
|
||||||
|
const filePath = path.join(__dirname, 'translations', `${languageCode}.json`);
|
||||||
|
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading translation:', error);
|
||||||
|
if(languageCode !== 'en') {
|
||||||
|
return loadTranslation('en'); // Fallback to English if the specific language file is missing
|
||||||
|
}
|
||||||
|
return {}; // Fallback to empty object if language file is missing
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user