FIGURE 1Same window internationalized in two languagespiler installer (lccwin32.exe) with the manual,but also the documentation installer(lccdoc.exe). It’s a command-line compiler thatcomes with a simple yet very capable IDE (andeven includes a GUI builder).At the very beginning we ran into someissues with the LCC-WIN32 resource compilerfailing to compile strings larger than 255 characters(quite common for some of our Frenchmessages). What happened next made me abeliever in open source. I contacted JacobNavia about the problem around 5 p.m. EST viae-mail. Despite the time difference (Franceversus Canada), he had a fixed version for methe next morning. My congratulations go out toJacob for providing such superb support for histool.Please refer to the sidebar, Installing andSetting Up LCC-WIN32, for a detailed list of thesteps required to install LCC-WIN32 and set upa project in it that you can use to maintainresource strings and compile them into a DLL.Seeing It All in ActionPlease download the LANGUAGE.PBL fromwww.sys-con.com/pbdj/sourcec.cfm. It containsthe class N_CST_LANGUAGE in which allthe required APIs are already set up for you. Italso includes a small test application thatprompts you to enter any of the two DLLs supplied(English.dll and Polish.dll, for example)and displays an internationalized window inwhatever language the selected DLL was compiledin (see Figure 1).Note that the test window doesn’t containFIGURE 2LCC-WIN32 resource editor outputoptionsany hard-coded internationalization logic;instead it’s encapsulated in the ancestor visualobjects (command button, label, multilineedit, etc.). They automatically translate themselvesupon creation using a resource IDembedded in their text label. This simpleapproach allows you to visually enter resourceIDs in the PowerBuilder GUI builder instead ofcoding them by hand, making the wholeprocess faster and more productive.INSTALLING AND SETTING UP LCC-WIN321. Install LCC-WIN32 using the installer EXE. I recommend installing intothe default directory (usually “C:\lcc”) to avoid installing into a directorywith spaces embedded in its name.2 After installing, start up the lcc-win IDE (Wedit) using the shortcut inStart—>Programs—>lcc-win32.3. After Wedit starts up, create a new project using File—>New—> Project….4. Choose a project name.5. Define the project properties (namely, the source directory in whichyou want your files to be compiled). Be sure to select the “Type ofProject” as “Dynamic Link Library (dll)”.6. When prompted whether to create an application skeleton, select“Yes.”7. Wedit displays a summary of the options for your project. Please notethe “Resource file” field at the bottom. It’s the actual resource file we’llbe maintaining and then compiling into a DLL.8. You’re then prompted for the default compiler settings; select “OK” toaccept them.9. Select “OK” to accept the default linker settings.10. Select “Finish” to accept the default debugger settings and completethe wizard. This will create the stub C code necessary to compile aDLL. No other C coding on our part is required; Wedit makes theentire process very simple.11. Create a resource file within the project using the Design—>Open/New… menu option and then type in the required name of theresource file (it can be anything you want, but I keep it the same as theproject name). This opens the Wedit resource editor, which can be usedto create all types of resources, not just strings. This editor is gearedmore toward creating dialogs, menus, etc., but you’ll only be using it tomaintain the string table of all phrases you want to internationalize. Toaccomplish that, change a few of the default resource settings.12. Invoke the Design—>Output menu option, which pops up the outputoptions dialog. Make sure the “RC ASCII resource file (.rc)” option isset up and flagged as “Generate,” as in Figure 2. Select “Validate” tosave the settings.13.Our next step is the actual creation of a string resource. To accomplishthis we need to go to Design—>New—>strings. This opens the StringTable editor where we can finally start entering string phrases with theresource IDs that identify them.14. To start adding strings, select the “Add” action on the right-hand sideof the window, which prompts you for the resource string to enter aswell as its ID (see Figure 3).The “Value” field is the resource ID; the “Content” field is the actualstring phrase. Selecting “OK” saves the value to the resource file.Using this resource editor we can add all the string phrases requiredby our application.15. After you’re finished, select “Save” to save your changes to the file.Obviously, you can reopen the same resource file later from withinWedit and add any new phrases that you might need later.16. To let LCC-WIN32 know that this resource file needs to be compiledwith the DLL, you need to add it to the project. This is a one-timeaction that you need to perform only after creating the file for the firsttime. It can be accomplished via the Project—>Add/Delete Files…menu option, which in turns brings up the dialog box shown in Figure4, where you can add the newly created *.RC file to the project.Simply select the “Add” button and select your *.RC file. Select the“Validate” button when you’re finished.17. At this point we already have a base C project and a base resource filein which we can keep adding new strings. To compile both of theminto a DLL we simply need to invoke the Compiler—>Compile “project_name.c”option. This compiles the DLL and makes it ready for youto use in your PowerBuilder application. The compiled DLL is locatedin the “\lcc” subdirectory of your project’s base directory.16PBDJ volume9 issue4www.SYS-CON.COM/pbdj/
Building an Internationalization Framework Basedon Resource DLLsIn my next article I’ll discuss creating an internationalization frameworkbased on resource DLLs that takes care of translating all window controlsand DataWindow objects, as well as resizing them dynamically at runtime toproperly display internationalized text regardless of its length (which variesfrom language to language). It will also cover the differences between resizingregular window controlsand DataWindow elements,which require a totally differentapproach due to theFIGURE 3FIGURE 4Resource string editorProject setupWindows APIs that areinvolved. I’ll also cover thecoding and layout issuesinvolved in developing internationalizedapplications aswell as a few obscurePowerBuilder issues you needto be aware of in order todeliver a professional, polishedproduct. Currently, weare successfully using such aframework in production,supporting three differentlanguages with more to come.SummaryTo recap, you’ve now seen how to use resource DLLs in PowerBuilder codeand how to create them using the LCC-WIN32 Wedit IDE. In other words, youhave everything you need to start fully integrating resource DLLs into yourapplication and using them as a primary means of internationalization. Again,that’s just one use for resource DLLs. Now that you know how to create and usethem, you have another powerful tool to add to your application developmenttoolkit.Stay tuned and happy internationalization! ▼AUTHOR BIOJacek Furmankiewicz is a PowerBuilder R&D supervisor at the Montreal office of STS Systems, an NSB company.His team is responsible for developing applications for some of the largest retailers in North Americaand Europe. Jacek has been using PowerBuilder since version 4.0 in Sybase, Oracle, and Microsoft SQL Serverenvironments.jfurmankiewicz@stssystems.comListing 1stringls_textunsignedlonglul_dll_handle//fill the string variable with spaces – ALWAYS neededwhen working with Windows APIsls_text = Space(512)//load the DLL into memorylul_dll_handle = This.LoadLibraryA("C:\program files\myapp\french.dll")//make sure the DLL loaded properlyIF lul_dll_handle > 0 THEN//fetch a resource string from it, e.g. string # 1045This.LoadStringA(lul_dll_handle,1045,ls_text,512)//unload the DLL from memoryThis.FreeLibrary(lul_dll_handle)END IF//display the text for resource IDsMessagebox("TEST",ls_text)Download the Code!The code listing for this article can also be located atwww.sys-con.com/ pbdj/www.SYS-CON.COM/pbdj/PBDJ volume9 issue417