Registering files when the application is running
You can switch between several
.mpr files while your application is running. For example, suppose you have a view for opening your application in different languages:
To enable switching between languages, add an instance script to this new view:
languageToggle
| files choice group |
files := #('aaadde10.mpr' 'aaaddg10.mpr').
choice := (self subpartNamed: 'Radio Button Set1') selectionIndex.
group := AbtNlsGroup new openOn:
AbtNLSCoordinator locateFileUsingNlsPath: (files at: choice)) fullName].
(AddressView newInShellView)
nlsGroup: group;
openWidget
This script reads the toggle selection and opens a window in your application that displays text in the selected language. Connect the clicked event for Open to the script.
Next, add an instance variable to the class definition for the view you are translating. For AddressApplication, change the class definition for AddressView to the following:
AbtAppBldrView subclass: #AddressView
instanceVariableNames: 'nlsGroup'
classVariableNames: ''
poolDictionaries: ''
Finally, add get and set instance scripts for the instance variable to the view class. The scripts might read as follows:
nlsGroup
^nlsGroup
nlsGroup: aGroup
nlsGroup := aGroup
You need these get and set methods because ordinary syntax, such as (anyobj getMRI: index) will not behave the way you want in this case. The default message fetching mechanism assumes a single language for the entire image. To retrieve messages in the appropriate language for each view, the view must hold on to an instance of AbtNlsGroup opened against the correct language file. Now, instead of writing mri := self getMRI: index group: groupName, you write mri := self nlsGroup getMRI: index .
If this application displays AddressView in two languages, but won't toggle back to the first language choice, select NLS > Rebind Image Strings from the Tools menu of the Transcript or evaluate AbtNLSCoordinator forceRelocalizationOfSeparatedConstants. Then, retry the toggle.
Last modified date: 02/16/2021