The following examples show you how to use VBA scripting that allows you to change the displayed language in your pictures when they are opened in run mode.
Example 1 shows you how to set the script at the global level (with SetLanguage). That is, all pictures that have an exported language file for the set language will display the text in that language when opened in run mode.
Example 2 shows you how to set the script to open a specific picture in run mode (with TranslateOnOpen, LanguageDesired, and SwitchLanguage) and display the text in the desired language.
Example 3 shows you how to switch the language for a single open picture, dynamically in run mode (with SwitchLanguage).
TIP: If you want to re-use these examples be sure that you review the important items listed on the Translating Picture Text topic before doing so, to ensure your configuration is correct.
Example 1: Configure Global Language for all Pictures to Open in Run Mode
The following example shows you how to create a picture that allows you to globally switch between languages while in run mode, in this case English and Spanish. After you switch the language the first time, any picture you open from that point onward displays in the specified language, provided a language file exists. You must close the picture and click another language button to switch the language again. With this example, you must manually open and close your pictures in run mode.
NOTE: This example assumes that English is the default language that the pictures are created in.
IMPORTANT: If you are using the iFIX WebSpace, it is recommended that you configure the language settings at the individual picture-level. If you instead configure them globally using this example, you will reset the language across all pictures for all users. This may be undesirable for your web users. For steps on picture-level configuration, refer to the second example below.
- In the iFIX WorkSpace configure mode, open the User Preferences and click the Picture Preferences tab.
- In the Cache area, clear the Enable Picture Caching check box if is enabled. This check box must be disabled if you want to re-open the same picture in the new language, after changing the languages.
- In the Picture Translation area, select the Translate Picture on Open check box, and in the Language drop-down list select Default.
- Create a new picture with two push buttons labeled "Open Pictures in English" and "Open Pictures in Español", as in the following picture.
Language Buttons
- In configure mode, right-click the Open Pictures in English push button and choose Edit Script. The Visual Basic Editor appears.
- Enter the following script to set the global language:
SetLanguage LANG_English
- Repeat steps 5 and 6, with the Open Pictures in Español button, but replace the SetLanguage LANG_English line with SetLanguage LANG_Spanish.
- Close the Visual Basic Editor and save the picture with a unique name.
- Add some English text to the picture, and save the picture.
- Export Spanish language files for the pictures that have text you want displayed in Spanish. For steps, refer to the Exporting Multiple Language Files section.
- In Notepad, open the Spanish language CSV file for the picture that you generated in the previous step, and provide translations for the picture text. For steps, refer to the Editing a Language File section.
- Switch to run mode.
- Click the Open Pictures in Español button. Any picture that you open after clicking this button will display the English picture text in Spanish, if the picture has a Spanish CSV file.
NOTE: To display Spanish text for pictures that were opened before clicking the button, close and re-open them. For example, if you close the picture we created in these steps and then re-open it, the text displays in Spanish.
- To switch back to English, close any open pictures except the push button picture with the language settings.
- Click the Open Pictures in English button and then reopen each picture. The text displays in English.
NOTES:
- Only one instance of a picture can be open at a time; you must close a picture before opening it to display the text in a different language.
- If a picture does not have a language file for the language you are displaying in, the text will remain in the default language in which it was created.
- You can create as many push buttons as you want to switch between multiple languages.
Example 2: Open a Single Picture in a Desired Language in Run Mode
The following example shows you how to create a picture with push buttons that allow you to open another picture in run mode and display its text in the desired language; in this case English and Spanish. In this example, only the picture, MyPicture, will open when either of the buttons is clicked and you can easily switch between English and Spanish. The OpenPicture command will open multiple instances of the same picture, so that you can have more than one language version of a picture open at the same time.
NOTE: This example assumes that English is the default language that the pictures are created in.
IMPORTANT: If you are using the iFIX WebSpace to open a picture, be aware that other pictures already open do not change languages when you open a picture. The language changes only when you open the picture.
TIP: If you want to re-use this example be sure that you review the important items listed on the Translating Picture Text topic before doing so.
- Create a picture with text and name it MyPicture.grf.
- Add two push buttons labeled "Open MyPicture in English" and "Open MyPicture in Español", as in the following picture.
Language Buttons
- In configure mode, right-click the Open MyPicture in English push button and choose Edit Script. The Visual Basic Editor appears.
- Enter the following script to set the TranslateOnOpen, LanguageDesired, and SwitchLanguage:
Dim pic As Object
OpenPicture "MyPicture.grf", , , , , , , , True
Set pic = Application.ActiveDocument.Page
pic.Translateonopen = False
pic.LanguageDesired = 9
pic.SwitchLanguage
- Repeat steps 3 and 4, with the Open MyPicture in Español button, but replace the pic.LanguageDesired = 9 line with pic.LanguageDesired = 1034 (1034 is the enumeration that represents Spanish, where as 9 represents English).
NOTE: For a listing of the enumerations for all supported languages (also called LCIDs) refer to the Language Letter Acronyms table in the Exporting and Importing Language Files topic.
- Close the Visual Basic Editor and save the picture with a unique name.
- Add some English text to the picture, and save the picture.
- Export a Spanish language file for MyPicture.grf.
- Open the language file in Notepad and translate the picture text to Spanish. For steps, refer to the Editing a Language File section.
NOTE: If list separator is comma in your local regional settings, you can use Microsoft Excel to edit your .CSV files. Otherwise, it is recommended that you use Notepad to edit your .CSV files. It is important that you use the proper text editor, so that the list separator, a comma, gets saved properly using your operating system's native regional settings. If you are unsure of your settings, use Notepad to edit your .CSV files.
- Make sure the Translate Picture on Open check box on the Picture Preferences tab of the User Preferences dialog box is cleared.
- Switch to run mode and open the picture with the push buttons.
- Click the Open MyPicture in Español button. MyPicture.grf opens with the text displayed in Spanish.
- From the Window menu, choose Tile Vertical to view both pictures.
- Click the Open MyPicture in English button. The text in MyPicture.grf displays in English.
NOTES:
- If a picture does not have a language file for the language you are displaying in, the text will remain in the default language in which it was created.
- You can create as many push buttons as you want to switch between multiple languages. Be sure that you review the important items listed on the Translating Picture Text topic before doing so, however.
Example 3: Switch the Language of Single Picture to a Desired Language in Run Mode
In the following example, two buttons are created to dynamically switch the language on the currently open picture in run mode regardless of the TranslateOnOpen and LanguageDesired properties. In this example, the SwitchLanguage method is used to perform this task.
- Create a picture and name it MyPicture.grf.
- Add two push buttons labeled "Switch to English" and "Switch to Español", as in the following picture.
Language Buttons
- In configure mode, right-click the Switch to English push button and choose Edit Script. The Visual Basic Editor appears.
- Enter the following script to set the language:
Me.SwitchLanguage 9
- Repeat steps 3 and 4, with the Switch to Español button, but replace the Me.SwitchLanguage 9 line with Me.SwitchLanguage 1034 (1034 is the enumeration that represents Spanish, where as 9 represents English).
NOTE: For a listing of the enumerations for all supported languages (also called LCIDs) refer to the Language Letter Acronyms table in the Exporting and Importing Language Files topic.
- Close the Visual Basic Editor and save the picture with a unique name.
- Add some English text to the picture, and save the picture.
- Export a Spanish CSV language file for your picture, so you can provide translations for the text you added in the previous step. For steps, refer to the Exporting a Single Language File section.
- Export an English CSV language file for your picture, so that English text displays when you switch picture languages.
NOTE: For each language that you want to use in your picture, prepare a translation file. For example, if your picture has English, Spanish, and French, you need to create a translation file for English, Spanish, and French. To create a translation .CSV file, refer to the Exporting a Single Language File section.
- Open the Spanish CSV language file in Notepad and translate the picture text to Spanish. For steps, refer to the Editing a Language File section.
NOTE: If the list separator is a comma in your local regional settings, you can use Microsoft Excel to edit your .CSV files. Otherwise, it is recommended that you use Notepad to edit your .CSV files. It is important that you use the proper text editor, so that the list separator, a comma, gets saved properly using your operating system's native regional settings. If you are unsure of your settings, use Notepad to edit your .CSV files.
- Make sure the Translate Picture on Open check box on the Picture Preferences tab of the User Preferences dialog box is cleared.
- Switch to run mode and toggle between the two languages:
- Click the Switch to Español button. Your picture displays text in Spanish.
- Click the Switch to English button. Your picture displays text in English.
NOTES:
- If a picture does not have a language file for the language you are displaying in, the text will remain in the default language in which it was created.
- You can create as many push buttons as you want to switch between multiple languages. Be sure that you review the important items listed on the Translating Picture Text topic before doing so, however.