Widget Translations
The Widget Translation Management system allows you to create multilingual widgets that automatically display content in the user's preferred language. This comprehensive translation system provides a table-based UI for managing translations across multiple languages with ease.
Overview
Widget translations enable you to:
- Define translation keys and values for multiple languages
- Use a table-based interface with inline editing
- Navigate efficiently using keyboard shortcuts (Tab/Enter)
- Automatically detect translation keys used in your widget layout
- Support any language code (e.g., en, de, fr, es)
Accessing the Translations Tab
- Navigate to your widget editor
- Click on the Translations tab
- Start by adding your first language
Managing Languages
Adding a Language
- Click the Add Language button
- Select a language from the dropdown (e.g., English, German, French, Spanish)
- Or enter a custom language code (e.g.,
pt-BRfor Brazilian Portuguese) - Click Add to create the language column
Removing a Language
- Click on the language code header in the table
- Select Delete Language from the dropdown menu
- Confirm the deletion
Deleting a language will remove all translations for that language. This action cannot be undone.
Managing Translation Keys
Adding a Translation Key
You can add translation keys in two ways:
Method 1: Manual Entry
- Click in the "Click to add" field at the bottom of the table
- Enter your translation key (e.g.,
greeting,button.submit,error.message) - Press Enter to create the key
- Click on the cells to add translations for each language
Method 2: From Layout Detection
The system automatically detects translation keys used in your widget layout using Handlebars AST parsing. Missing keys are highlighted in amber at the top of the table:
- Keys detected in your layout appear with an amber background
- Click on any cell to add a translation
- Use the + button to add the key to all languages at once
Use descriptive, hierarchical key names:
greeting- Simple keysbutton.submit- Nested keys using dot notationerror.notFound- Categorized keys
Editing Translations
- Click on any cell to start editing
- Type your translation text
- Press Enter or Tab to save and move to the next field
- Press Escape to cancel editing
Keyboard Navigation
The translation table supports efficient keyboard navigation:
| Key | Action |
|---|---|
| Tab | Save current cell and move to the next cell (right) |
| Shift + Tab | Save current cell and move to the previous cell (left) |
| Enter | Save current cell and move down to the next row |
| Escape | Cancel editing and close the input |
When adding translations row by row, use Enter to move down. When translating across languages, use Tab to move right. On the last row, pressing Enter will automatically focus the "new key" input field.
Deleting Translation Keys
- Click the trash icon in the Actions column
- Confirm the deletion
- The key will be removed from all languages
Using Translations in Your Widget
The t Handlebars Helper
Use the {{t 'key'}} helper in your widget layout to display translated text:
Language Detection
The widget automatically uses the appropriate language based on:
- Staffbase Branch Configuration - The primary language set in your Staffbase environment
- Browser Language - Falls back to the user's browser language if configured
- Default Language - Uses the first language in your translations if no match is found
Example Translation Setup
Here's a complete example of a multilingual widget:
Translation Keys:
| Key | English (en) | German (de) | French (fr) |
|---|---|---|---|
greeting | Hello! | Hallo! | Bonjour! |
button.submit | Submit | Absenden | Soumettre |
button.cancel | Cancel | Abbrechen | Annuler |
message.success | Successfully saved! | Erfolgreich gespeichert! | Enregistré avec succès! |
Widget Layout:
Automatic Layout Key Detection
The translation system uses Handlebars AST (Abstract Syntax Tree) parsing to automatically detect all {{t 'key'}} helpers in your widget layout.
How It Works
- The system parses your Handlebars template
- Identifies all
thelper calls - Extracts the translation keys
- Highlights missing keys in amber at the top of the translation table
Missing Keys Indicator
When keys are detected in your layout but not in your translation table:
- An amber warning banner shows the count of missing keys
- Each missing key appears as an amber row at the top of the table
- You can add translations directly or use the + button to add to all languages
The system automatically scans your layout whenever you switch to the Translations tab or modify your template. Keys used in conditionals {{#if}}, loops {{#each}}, and nested helpers are all detected.
Best Practices
Organization
- Group related keys using dot notation (e.g.,
form.email.label,form.email.placeholder) - Use consistent naming conventions across your widgets
- Keep translation keys descriptive and self-documenting
Maintenance
- Add all languages before starting translations to avoid incomplete coverage
- Regularly check for missing layout keys (amber highlighted rows)
- Use the keyboard shortcuts for faster data entry
Quality
- Keep translations concise to fit within your widget design
- Test your widget in all supported languages
- Ensure translations maintain the same meaning and tone
Performance
- The translation system is optimized for runtime performance
- Translations are bundled with your widget (no additional API calls)
- Multiple languages don't impact widget loading time
Common Use Cases
Multi-Language Forms
Error Messages
Dynamic Content
Troubleshooting
Keys Not Detected
If your translation keys aren't being detected automatically:
- Ensure you're using the correct syntax:
{{t 'key'}} - Check that your layout doesn't have syntax errors
- Verify the key is wrapped in single quotes:
'key'not"key"
Translations Not Showing
If translations aren't displaying in your widget:
- Verify the key exists in at least one language
- Check the browser console for errors
- Ensure your widget is using the latest version
Missing Translations
If a translation is missing for a specific language:
- The system will fall back to the first available language
- Consider adding a default language with all keys defined
- Check the amber highlighted rows for missing translations
Additional Resources
If you encounter issues with the translation system, contact support or check the Widget Builder documentation for more detailed examples.