Tips_gui   >   Misc   >   String Tables

String Tables

String tables can be used to support multiple languages. String tables are a good discipline to follow, even if you are supporting only one language.

Books on GUI recommend that developers use some sort of a common phrase dictionary for all the labels, titles, prompts, and messages throughout the application. By using a centralized phrase dictionary you are better assured that the same terminology is used for the same things throughout your application. This is especially critical for applications being developed by multiple programmers. The user becomes confused when in one window you refer to the a certain menu as the Application Menu and in another window you refer to it as Main Menu.

String tables could also be used for operating system sensitive terminlogy.
e.g. Mac vs. Win vs. Unix. Ctrl-Click vs. Right-Click

At the time of writing this section in StudioTips, finding the information on String Tables took some effort. Eventually I found a Tech Note on the Omnis web site at: www.omnis.net/develop/resources/notes/technotes.html

You can also download two string table demo libraries from Omnis: strtest.lbs and Table.lbs

This section of StudioTips goes through the information provided in the Tech Note giving demos and suggestion of how to implement String Tables. Each String Table function is listed and explained.

String Table Editor

The String Table Editor is a window interface which Omnis has created to assist developers in creating, editting, and saving String Tables.

To open the String Table Editor look under the Tools menu > Add-Ons > String Table Editor... Look through the File and Tools menus. Hold your mouse of the toolbar buttons to review all the String Table Editor functions that Omnis has provided for you to use.

When you Save a string table, Omnis sorts the table on the ID column just prior to saving it. This is done to speed lookups when the string table is being used.

For editing an existing string table, you have the option of exporting it, editing it in Excel and then importing it. You might find it easier to create your string table in Excel and then import it.

Tip

If you aren't happy with the String Table Editor you can roll your own. Click the Run Demo button in the StudioTips Browser to open the StudioTips custom String Table Editor.

Using String Tables

So, how do you go about using string tables in your own application? Well, as usual there are many ways. Some developers choose to create and store the string tables as lists which are stored in the data file, rather than using actual string table files stored on disk. In that case you would use $loadtablefromlist instead of $loadstringtable.

My own preference at this stage is to save and load the string tables as files.

To keep your string tables manageable, it is recommended that you have separate string tables for various categories. For example you can have separate string tables for:

You should store all the string table files in a separate directory below the main library of your application. For StudioTips I created a string_tables folder located inside the demos folder.

Even if you are currently only developing your application in one language, the use of string tables can be a good discipline for keeping your terminology consistent throughout your application.

String Tables Mapped to Schema Columns

As I was adding labels to the entry fields on a window the idea occurred to me to create a string table for each server table and to use the server table column name as the string table ID column. Every colum in my database would be mapped to a unique string table row.

I have embarked on a mission to create a string table for every SQL table that has data which is displayed on a window or report.

  1. The string table file name is the server table name.
  2. The ID column of the string table is the SQL table column names,
  3. The different language columns contain the exact label wording as I want it displayed in window labels for that column name.

For example, a server table column name of ChequeNumber in the en-US (English-US) column will say Check Number and in the en-GB (English-British) column will say Cheque Number.

In your windows and report instead of entering the actual field label text, you can use a kText field and put the following square bracket notation:

[StringTable.$gettext('SQLTable.ColumnName')]

No further thinking or coding is required! When the window opens the labels will display the correct label text for the language column that was set when the library was opened. If I or my client want to change the label for the server table column LastName from Last Name to Surname ... no problem. Change it in the string table and every place LastName is displayed will be changed from Last Name to Surname.

To speed up creation of string tables which match existing schema classes, I created a String Table Editor which allows you to select a schema class and then using a context menu call a method which builds a string table list with the ID and 1st language column already filled in. You can then edit and save the string table as a file.

StudioTips includes the custom String Tables Editor with the Create String Table from Schema Class feature. Click the Run Demo button in the StudioTips Browser to open the StudioTips custom String Tables Editor.

String Table Labels

Omnis provides a handy String Table Label external component which works well with string tables. You will find the String Table Label in the Component Store under Background Components.

The String Table Label has a property $rowid under the Custom tab where you enter TableName.ID

One alternative is to use "text" background objects and enclose the $gettext function in [square brackets].
Example: [StringTable.$gettext('TableName.ID')]

String Table Column Names

If you are using string tables for supporting various languages, you may want to use the same language abbreviations used by the web browsers. Why bother figuring out codes for the various languages, when there is already a standard being used.

To find out the code, open the Preferences in your web brower and click on the Languages preferences setting. Click on the Add... button, and you will be prompted with a list of languages and their abbreviations.

Warning

Don't include parenthesis () in your string table column names ... the brackets will mess up your notation.

Headed List Column Headings

The headed list $columnnames property doesn't evaluate [] square bracket $gettext notation. One workaround is to build the $columnnames string in the $construct method of the headed list.

Click Run Demo to see how this can be done.

$colcnt

Do StringTable.$colcnt([TableName])

Returns the column count for TableName.

$getcolumnname

Do StringTable.$getcolumnname(TableName)

Gets the column name for the current column.

$getcolumnnumber

Do StringTable.$getcolumnnumber(TableName)

Gets the column number for the current column.

$gettext

Do StringTable.$gettext('[TableName.]ID') Returns Text

Gets the text in the current column of the specified String Table for the row matching ID.

You can use square brackets in a kText label:

[StringTable.$gettext('TableName.ID')]

$loadcolumn

Do StringTable.$loadcolumn(ColumnName,TableName,Path)

Creates a string table file using a single column of an existing string table.

$loadlistfromtable

Do StringTable.$loadlistfromtable(TableName) Returns List

Loads a string table already in memory to a list variable.

$loadstringtable

Do StringTable.$loadstringtable(TableName,Path)

Loads an existing string table into memory from an existing string table file.

Note: If the string table has already been loaded, you must first $unloadstringtable. Trying to load the same string table will result in an error.

$loadtablefromlist

Do StringTable.$loadtablefromlist(TableName,Path,List) Returns ErrCode

Creates a string table from a list variable. It should be noted that the table is created in memory at this point. To save the table, use $savestringtable.

Although this command requires a path, it doesn't actually create the file until you issue the $savestringtable.

If the String Table has already been loaded, you must first $unloadstringtable. Trying to load the same string table will result in an error.

$redraw

Do StringTable.$redraw(WindowInstanceRef.$hwnd)

Redraws the string table labels on an entire window.

Warning

Not including the .$hwnd will cause Omnis Studio to crash. (I know from experience!)

$redrawAll

Redraw all windows after selecting a new string table.

This is not a string table function. This is a method you can create/use for redrawing all the string table labels in all the open windows.

$removestringtable

Do StringTable.$removestringtable(Path)

Deletes a string table stored on disk.

Warning

This function really does delete the string table file!

$rowcnt

Do StringTable.$rowcnt([TableName])

Returns the row count for TableName.

$savestringtable

Do StringTable.$savestringtable(TableName)

Saves a string table which has been previously created.

Note: A path name is not required when saving. Pathnames are only specified when creating string tables.

If you had a new string table in a list, the process of creating the new string table file on disk would be as follows:

; Saving a string table to disk.

; First unload the String Table if it has already been loaded.
Do StringTable.$unloadstringtable(TableName)

; Load the list and path into the String Table to be held in memory.
Do StringTable.$loadtablefromlist(TableName,Path,List)

; The path was loaded into the String Table, so it's already there when you $savestringtable().
Do StringTable.$savestringtable(TableName)

$setcolumn

Do StringTable.$setcolumn([StringTableName.]ColumnName)

Sets the current column to ColumnName. This may be either a name or a number.

Note: ColumnName is case sensitive. If multiple string tables are being used then the format needs to be TableName.ColumnName

Do StringTable.$setcolumn("Table1.French")

or

Do StringTable.$setcolumn("Table1.3")

$unloadall

Do StringTable.$unloadall()

Unloads all string tables from memory.

This function is optional, as all String Tables are automatically unloaded when Omnis quits.

$unloadstringtable

Do StringTable.$unloadstringtable(TableName)

Unloads a string table from memory.

This function is optional, as all string tables are automatically unloaded when Omnis quits.