4115
Example of a multi-language widget application with IDL

This Article shows an example of a widget application in IDL that will support different languages depending on the OS language
1. Identify the OS language programmatically: default language will be English in the example below
Result = LOCALE_GET( )
if STREGEX(result,'(.*)_.*\..*',/BOOLEAN) then $
language=(STREGEX(result,'(.*)_.*\..*',/EXTRACT,/SUBEXPR))[1] $
else $
language='English'
2. Create the language library: all language files described below should be saved in the same directory
A. Save the text below in a file called langcat.dtd
****************************************
<!ELEMENT IDLffLangCat (LANGUAGE*)>
<!ATTLIST IDLffLangCat
APPLICATION CDATA #IMPLIED
VERSION CDATA #IMPLIED
AUTHOR CDATA #IMPLIED
DATE CDATA #IMPLIED
>
<!ELEMENT LANGUAGE (KEY*)>
<!ATTLIST LANGUAGE
NAME CDATA #REQUIRED
>
<!ELEMENT KEY (#PCDATA)>
<!ATTLIST KEY
NAME CDATA #REQUIRED
TYPE CDATA #IMPLIED
>
****************************************
B. Create an English language catalog : save the text below in the file called english.cat . All language catalogs should have the .cat extension
****************************************
< ?xml version='1.0' encoding='ISO8859-1'?>
< !DOCTYPE IDLffLangCat SYSTEM 'langcat.dtd'>
< IDLffLangCat APPLICATION="Widget Lang" VERSION="1.0" AUTHOR="Exelis VIS- Support">
< LANGUAGE NAME='English'>
< KEY NAME='MENU_FILE'>File</KEY>
< KEY NAME='MENU_IMPORT'>Import ASCII</KEY>
< KEY NAME='MENU_SAVE'>Save sondes</KEY>
< KEY NAME='MENU_OPTIONS'>Options</KEY>
< /LANGUAGE>
< /IDLffLangCat>
****************************************
C. Create a second language catalog - French for example-: save the text below in the file called francais.cat. All language catalogs should have the .cat extension
****************************************
<?xml version='1.0' encoding='ISO8859-1'?>
<!DOCTYPE IDLffLangCat SYSTEM 'langcat.dtd'>
<IDLffLangCat APPLICATION="Widget Lang" VERSION="1.0" AUTHOR="Exelis VIS- Support">
<LANGUAGE NAME='French'>
<KEY NAME='MENU_FILE'>Fichier</KEY>
<KEY NAME='MENU_IMPORT'>Fichier de sondes ASCII</KEY>
<KEY NAME='MENU_SAVE'>Sauvegarder les sondes</KEY>
<KEY NAME='MENU_OPTIONS'>Les Options</KEY>
</LANGUAGE>
</IDLffLangCat>
****************************************
D. Create a third language catalog - Russian for example-: save the text below in the file called russian.cat. Make sure that this file is saved with UTF-8 encoding. It is an option when you save a file using most text editors. All language catalogs should have the .cat extension. NOTE: In order for this to work properly, several settings must be changed in the Region and Language portion of the Control Panel. See the following help article for instructions on how to get Russian characters to work: http://www.exelisvis.com/Support/HelpArticlesDetail/TabId/219/ArtMID/900/ArticleID/4683/4683.aspx
It should also be noted that the encoding for the language catalog has to be altered for Russian characters to be read from the language catalog, This is set on the first line of each language catalog.
****************************************
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE IDLffLangCat SYSTEM 'langcat.dtd'>
<IDLffLangCat APPLICATION="Widget Lang" VERSION="1.0" AUTHOR="Exelis VIS- Support">
<LANGUAGE NAME='Russian'>
<KEY NAME='MENU_FILE'>привет </KEY>
<KEY NAME='MENU_IMPORT'>э оборотное</KEY>
<KEY NAME='MENU_SAVE'>і десятеричное</KEY>
<KEY NAME='MENU_OPTIONS'>привет </KEY>
</LANGUAGE>
</IDLffLangCat>
****************************************
3. Create the code to build the widget application: the example is composed of a base widget including a menu and a button
As a test you can comment-uncomment line 4 or 5 of the code to test the English or French library. When it works you can replace these lines by the command line described at step 1 of this document.
This codeonly displays the widget : it does not include an event handler
This code example should be saved in the same directory as the language catalogs.
*******************************************
PRO test_widget_lang
path=FILE_DIRNAME((ROUTINE_INFO('test_widget_lang',/SOURCE)).path)
language='English'
;language='french'
;language = 'russian'
oCatalog=OBJ_NEW('IDLffLangCat',language,APP_NAME='Widget Lang',APP_PATH=path)
wBase=WIDGET_BASE(TITLE='Widget_test' $
,MBAR=wMenuBar,COLUMN=1,/BASE_ALIGN_CENTER $
,xsize=300,ysize=100)
wFileButton=WIDGET_BUTTON(wMenuBar,VALUE=oCatalog->Query('MENU_FILE'),/MENU)
wImportButton=WIDGET_BUTTON(wFileButton,VALUE=oCatalog->Query('MENU_IMPORT'))
wSaveButton=WIDGET_BUTTON(wFileButton,VALUE=oCatalog->Query('MENU_SAVE'))
wOptionsButton=WIDGET_BUTTON(wbase,VALUE=oCatalog->Query('MENU_OPTIONS'))
WIDGET_CONTROL,wBase,/REALIZE
END
*******************************************
____________________________________________________
Reviewed by DS on 7/23/2014