ErrorClass Multi-Language Capability

Top  Previous  Next

Because all error message text is defined in one place (ABERROR.TRN), it is easy to implement non-English error messages. For static (permanent) language translation, simply translate the English text in ABERROR.TRN to the language of your choice. Alternatively, for dynamic language translation, you may add an error definition block to ABERROR.TRN for each supported language. For example in ABERROR.TRN declare:

DefaultErrors  GROUP    !English error messages

              END

GermanErrors   GROUP    !German error messages

              END

Then at runtime, initialize the error manager with the appropriate error definition block. For example, you could override the Init method (defined in ABERROR.CLW) with something like this:

 INCLUDE('ABERROR.INC')               !declare ErrorClass

MyErrorClass  CLASS(ErrorClass)        !declare derived class

Init           PROCEDURE(BYTE PreferredLanguage)

             END

 

GlobalErrors      MyErrorClass         !declare GlobalErrors object

Language          BYTE                 !Language Flag

Language:English  EQUATE(0)            !English equate

Language:German   EQUATE(1)            !German equate

 

 CODE

 Language = GETINI('Preferences','Language',0)  !get language preference

 GlobalErrors.Init(Language)                    !GlobalErrors initialization

                                                !with preferred language

 

 

MyErrorClass.Init PROCEDURE(BYTE PreferredLanguage)  !New Init method

 CODE

 SELF.Errors &= NEW ErrorEntry        !allocate new Errors list

 CASE PreferredLanguage               !which language was selected

 OF Language:German                   !if German

   SELF.AddErrors(GermanErrors)       !add German errors to list

 ELSE                                 !otherwise...

   SELF.AddErrors(DefaultErrors)      !add default (English) errors

 END

Alternatively, you could call the AddErrors method to define additional errors for the selected language as shown in the following example.