Localization best practices
You can prepare an MDriven application for multiple languages and culture-specific formats by using the translation model pattern and the translation workflow described here; this page is for developers and administrators who maintain translated applications.
Internationalization is the preparation of an application to work across languages and cultures. Localization is the translated text and culture-specific presentation used for a selected language. In MDriven, translated values are resolved through the localization pattern.
Set up the translation model before adding translated text
Use the established localization pattern in your model. The pattern uses SysTranslatable objects for source values, SysTranslation objects for translated values, and SysTranslationLanguage objects for language codes.
For example, when the application contains the source text Save, MDriven can look up a SysTranslatable with the value Save, then return the SysTranslation connected to the requested SysTranslationLanguage.
In MDriven Turnkey, newer versions install IMDrivenUITranslation for you. If your system does not install it, install the translation service:
MDriven.Translation.MDrivenUITranslationImpl.Install(ecoServiceProvider);
Request translated text consistently
Use Translate where text must be shown in the user's selected language. An empty language argument requests translation in the current default language.
'Translate this text'.Translate('')
You can request a specific language code when you need to verify a translation. The following example looks for a translation of Translate this for sv-SE:
'Translate this'.Translate('sv-SE')
If no matching translation is found, MDriven retains the original value. Use clear source text because it is also the fallback shown when a translation is missing.
Collect missing translations from application use
Do not create every SysTranslatable object manually. Exercise the application paths that contain the text you want to translate, then spool the complete misses that MDriven has observed since startup or the previous spool operation.
'Whatever'.Translate('SPOOLMISSED')
For example, open a form that contains Save, Cancel, and Customer number, then run SPOOLMISSED. Maintain the created translatable values and add their translations for each required language.
Refresh translations after editors make changes
MDriven creates its translation dictionaries at system startup. Restart the system when you can schedule a restart so that newly added translations take effect.
When translators or administrators need to see changes without waiting for a restart, reset cached pages after updating translations:
'Whatever'.Translate('RESETCACHE')
RESETCACHE resets cached pages because they can contain translated text. On the next request, the pages are created again and can reflect the updated translations.
Keep language and culture decisions separate
The default language in MDriven Turnkey is set from the browser language, commonly a value such as en-US or sv-SE. You can force a default language in an action:
'Whatever'.Translate('DEFAULT=sv-SE');
Use SysCultureSettingsSingleton when you need separate control of culture and translation culture:
| Setting | Controls | Example |
|---|---|---|
Culture
|
What MDriven gives to the browser for rendering numbers and dates. | A decimal value can use a comma or a point as its decimal separator. |
TranslationCulture
|
The current SysTranslationLanguage used for translated text.
|
The interface can retrieve a Swedish translation while culture controls date and number rendering separately. |
You can make the SysCultureSettingsSingleton properties derived and let each user own values. DefaultDecimalDisplay adds a StringFormat for Angular, Blazor, or WPF when no format is already present. MetricImperial can affect the decimal precision used by this setting.
Map unsupported browser languages deliberately
Use CheckLanguageMapping(input:String):String on SysTranslateLanguage when the browser reports a language for which you do not maintain translations. Return a supported language rather than leaving the fallback implicit.
For example, an application designed in Swedish with English translations can map French browser languages to English:
if input.contains('fr') then
'en'
else
input
endif
Verify the full translation workflow
- Set the browser's web-page language to a supported language. The web-page language setting matters; changing only the browser display language may not provide the language needed by the application.
- Request a page that contains translated text and confirm that the expected language code resolves to the intended
SysTranslationvalue. - Test a source value without a translation and confirm that the original value remains visible.
- Add or change a translation, run
RESETCACHE, and request the page again to confirm that the new value appears. - Test number and date rendering separately from translated text when you use
SysCultureSettingsSingleton.
