Start simple translation approach
This commit is contained in:
36
index.js
36
index.js
@@ -65,13 +65,21 @@ DB.getDB.then((DB) => {
|
||||
|
||||
// route for Home-Page
|
||||
app.get('/', sessionChecker, async (req, res) => {
|
||||
if (req.userInfo) return res.json({
|
||||
try {
|
||||
const userInfo = req.userInfo;
|
||||
if(!userInfo) {
|
||||
// This should not happend, since the sessionChecker should redirect to login
|
||||
return res.status(401).json({ status: "Unauthorized" });
|
||||
}
|
||||
return res.json({
|
||||
status: "ok",
|
||||
userInfo: req.userInfo,
|
||||
profileInfo: req.profileInfo
|
||||
});
|
||||
// This should not happend, since the sessionChecker should redirect to login
|
||||
res.json({ status: "ok" });
|
||||
} catch (error) {
|
||||
console.error("Error processing / path", error);
|
||||
return res.status(500).json({ status: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
// 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
|
||||
app.post('/token/', sessionChecker, async (req, res) => {
|
||||
try {
|
||||
const profileid = getProfileId(req);
|
||||
let token = req.body.token
|
||||
DB.setProfileToken(profileid, token);
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
const { token } = req.body;
|
||||
// Validate token presence
|
||||
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
|
||||
|
||||
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