Start simple translation approach
This commit is contained in:
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