Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 7 Pages and Components

7.12 Creating multi-lingual applications

Scroll Prev Top Next More

DAQFactory has the ability to create multi-lingual applications.  Alas, it does not do the translation for you, but it does provide you with the tools to quickly and easily create translations of pages that can be changed at runtime by setting a system variable.  To take advantage of the translation features, you should prefix any string that will end up in an on screen display with @ followed by the default language form or, if you want, a simple name.  For example, if you had a variable value component, you might put @Pressure for the caption.  Without adding any languages to the documents available language, the variable value component will simply display with the caption Pressure.  But if you have other languages and you've enabled one as the current language, it will replace Pressure with new language equivalent.  This applies to captions, labels, units, and any other text that appears in a component.  

Translation also applies to string constants.  For example, if you did:

 

global string x = {"@Pressure", "@Temperature"}

the string would fill with "Pressure" and "Temperature" if no language is enabled, or the translated strings if one is enabled.  It is important to understand, though, that the substitution is done immediately.  If you are assigning a string constant to a property of a page component that would normally be translated there are issues as shown in this example:

 

component.MyTextComponent.strText = "@Once upon a time..."

This will assign the strText property of MyTextComponent with the translated value of "@Once upon a time..." which won't include the "@" in the front.  If you then change the language after doing this, MyTextComponent's strText property won't translate since its not marked with the @ sign.  To avoid this, you have to use two @ signs:

 

component.MyTextComponent.strText = "@@Once upon a time..."

In this case, DAQFactory will try and find a translation for "@Once upon a time..." when the assignment occurs, which presumably it won't.  The component now contains "@Once upon a time..." and when the component is drawn it will see the @ sign and try and translate "Once upon a time...".  Since the component contains the @ sign still, a change in language will still have effect.

Of course none of this works if you don't have language translations setup for your strings.  To create new languages and setup translations, go to Tools - Languages....  This brings up the Language Settings window:

image72

At the top is a drop down list of the current languages in this document.  To start, you'll need to click the Add button to add a new language.  You will be prompted for the language name.  This must be unique among languages, but is otherwise not subject to the normal limitations of DAQFactory names.  Once you have added a language you can start adding phrases.  Phrases are the strings in the default language you placed in the various components and script in your application.  Phrases do not include the opening "@" which is implied.  To add a phrase, type in the phrase in the box to the right, and then the translation of that phrase in the currently selected language.  Then hit Add to add the phrase to the list.  Continue as needed.  To delete a phrase, select it and hit the Del button.

There are several features to make things easier.  You may find it easier to keep a spreadsheet of all the phrases you use in your document.  If so, you can import and export from comma delimited (CSV) files a complete language phrase list.  The CSV file should contain two columns, the phrase and the translation.  The first row in the file should be a header and is ignored by the import routine.  The best way to ensure that your file is in the correct format is to export a small language file and then add your phrases to this file using a program like Excel.  If using Excel or another program that supports all the features of a CSV file, then you should be able to use carriage returns, commas, and quotes within your phrases and translations.  DAQFactory supports the proper escaping of these characters in the standard CSV format.  If using Excel, simply save your worksheet as a .csv file and Excel will do the rest.

Once you have created one language, instead of hitting Add to add a new language, you can press Copy to add a new language with an exact copy of the currently selected language.  You can then go through and edit the phrases of the new language as needed.

Languages are saved with your document.  When you start DAQFactory and load your document, DAQFactory will use the phrase specified in the components and strings (without the @) until you specify a different language.  To specify the working language use the system.language variable:

 

System.Language = "Klingon"

This setting is not case sensitive.  The change will occur immediately with the next screen refresh.  To reset back to the default phrases, simply specify a language that does not exist in this document.  There is also a function to list all the languages in the document:

System.GetLanguageList(): returns a string array with all the languages in this document.

This function could be used to populate a combobox to allow the user to select their language at runtime.  Then, if you added a language to your document, this combobox would automatically update.

Note: the @ marker only applies if it appears as the first character in a string.  If it appears elsewhere in the string, it will appear as a normal @ sign.  If you actually want a @ as the first character of a string, simply put two @'s.

Note: the tree list component does not translate.  The component must be pre-populated with translated strings.  This means that if you change the language and want the tree list to update, you will have to clear the tree list and repopulate it.  If you use strings marked for translation in a routine that populates the tree list, this should be easy.