Start simple translation approach

This commit is contained in:
Adolfo Reyna
2025-02-21 00:12:17 -05:00
parent 7902b75b5c
commit 1056a91c33
3 changed files with 53 additions and 13 deletions

5
translations/en.json Normal file
View File

@@ -0,0 +1,5 @@
{
"hello": "Hello",
"new_password": "This is your new password: {{password}}",
"login_link": "Log in here"
}

View 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
}
};