Step-by-step instructions for adding new language translations to O-ELIDDI
The O-ELIDDI application uses a comprehensive internationalization (i18n) system that supports multiple languages with easy extensibility. This guide provides step-by-step instructions for adding new language translations.
Before starting translation work, ensure you have:
/locales/
directory/locales/
directory in the project rootde.json
for German, it.json
for Italian)en.json
as your starting template:# Copy English template to new language file
cp locales/en.json locales/de.json
Open your new language file and translate each text string. Here's the basic structure:
{
"instructions": {
"title": "Your Translation Here",
"subtitle": "Your Translation Here",
"mainInstruction": "Translate this text...",
"step1": {
"title": "Your Translation Here",
"horizontal": "Instructions for desktop/horizontal layout",
"vertical": "Instructions for mobile/vertical layout"
}
},
"buttons": {
"submit": "Your Translation Here",
"start": "Your Translation Here",
"undo": "Your Translation Here"
}
}
<span class="emphasis">yesterday</span>
. Preserve HTML tags and only translate the text content.\"
. Use proper Unicode characters for accented letters.Update the default language in the application settings:
settings/activities.json
general
sectionlanguage
field:{
"general": {
"language": "de",
"other_settings": "..."
}
}
npm start
Open browser developer tools console and test specific translations:
// Test translation loading
await window.i18n.init('de');
// Test specific translation keys
console.log('Title:', window.i18n.t('instructions.title'));
console.log('Submit button:', window.i18n.t('buttons.submit'));
// Test with URL parameter
// Visit: http://localhost:8080?lang=de
You can test your language without changing the default setting:
http://localhost:8080?lang=de
http://localhost:8080/pages/instructions.html?lang=de
Test all major sections of the application:
Use the debug tools to check for missing translations:
// Load your language and test for missing keys
window.i18n.init('de').then(() => {
// Test various translation keys
const testKeys = [
'instructions.title',
'buttons.submit',
'modals.childItems.title',
'messages.loading',
'thankYou.title'
];
testKeys.forEach(key => {
const translation = window.i18n.t(key);
console.log(`${key}: ${translation}`);
// Check if it fell back to English (indicates missing translation)
if (translation === window.i18n.t(key, 'en')) {
console.warn(`Possible missing translation for: ${key}`);
}
});
});
Here's the complete structure you need to translate:
{
"instructions": {
"title": "Instructions",
"subtitle": "How to use this research tool",
"mainInstruction": "Think about activities you did <span class=\"emphasis\">yesterday</span> and create a timeline of your day.",
"step1": {
"title": "Select and Place an Activity",
"horizontal": "Choose an activity from the menu at the bottom of the screen, then click on the timeline to place it.",
"vertical": "Tap the (+) button in the bottom right corner to add activities to your timeline."
},
"step2": {
"title": "Adjust Time and Duration",
"horizontal": "Drag the ends of activities to adjust their start time and duration.",
"vertical": "Tap and drag activities to reposition them, or drag their edges to adjust timing."
},
"step3": {
"title": "Submit Your Timeline",
"description": "When you're satisfied with your timeline, click the Submit button to save your data.",
"submitHelp": "Submit your completed timeline"
}
},
"buttons": {
"submit": "Submit",
"start": "Start Timeline",
"undo": "Undo",
"next": "Next",
"previous": "Previous",
"close": "Close",
"addActivity": "Add Activity",
"undoTooltip": "Undo the last action"
},
"modals": {
"childItems": {
"title": "Select Sub-Activity",
"titleFor": "Select an option for \"{activityName}\"",
"noOptions": "No sub-activities available for this activity."
},
"customActivity": {
"title": "Add Custom Activity",
"placeholder": "Enter activity name...",
"addButton": "Add Activity",
"cancelButton": "Cancel"
}
},
"messages": {
"loading": "Loading...",
"error": "An error occurred while processing your request.",
"success": "Your timeline has been saved successfully!",
"offline": "You are currently offline. Your data will be saved when connection is restored.",
"dataUploaded": "Data uploaded successfully",
"uploadError": "Error uploading data. Please try again."
},
"activities": {
"selectActivity": "Select an activity",
"customActivity": "Custom activity",
"noActivitiesFound": "No activities found"
},
"thankYou": {
"title": "Thank You!",
"message": "Your timeline has been recorded successfully. Thank you for participating in our research.",
"footer": "You may now close this browser window."
}
}
horizontal
vs vertical
instructions are for different screen orientations:
Some strings contain {parameter}
placeholders like {activityName}
:
"Select option for {activityName}"
→ "Seleccionar opción para {activityName}"
Some translations contain HTML like <span class="emphasis">yesterday</span>
:
Problem | Solution |
---|---|
Text is cut off or overflows | Some languages are longer than English. Test translations on both desktop and mobile to ensure they fit properly. |
Special characters don't display correctly | Ensure your JSON file is saved with UTF-8 encoding and use proper Unicode characters. |
HTML markup is displayed as text | Check that you're using the correct data-i18n-html attribute for content that should render HTML. |
Translations don't appear | Check JSON syntax is valid (no trailing commas, proper quotes). Verify language code matches filename. Clear browser cache. |
Fallback to English occurs | Check that all translation keys exist in your file and match the exact key names used in the English version. |
{activityName}
) are preservedUse standard ISO 639-1 language codes for your translation files:
Language | Code | Filename |
---|---|---|
German | de | de.json |
Italian | it | it.json |
Portuguese | pt | pt.json |
Dutch | nl | nl.json |
Russian | ru | ru.json |
Japanese | ja | ja.json |
Korean | ko | ko.json |
Chinese | zh | zh.json |
Arabic | ar | ar.json |
Note: For regional variants, use the full locale code (e.g., pt-BR
for Brazilian Portuguese, zh-CN
for Simplified Chinese).
Need Help? If you encounter issues during translation, check the browser console for JavaScript errors, use the debug script to test specific translations, or compare with existing translations (Spanish/French) for reference.