Navigation: ABC Library Reference > TranslatorClass > TranslatorClass Methods >====== AddTranslation (add translation pairs) ====== | |
AddTranslation | ( | group | ) | |
text, translation |
AddTranslation | Adds translation pairs. |
group | The label of a structure that contains one or more text/translation pairs. |
text | A string constant, variable, EQUATE, or expression containing user interface text to search for. The TranslatorClass replaces each found text with its corresponding translation. |
translation | A string constant, variable, EQUATE, or expression containing the replacement text for the corresponding text. |
The AddTranslation method adds translation pairs to the runtime translation process.
The text is not limited to a single word; it may contain a phrase, or any text string, including TranslatorClass macros (see TranslatorClass Concepts–Runtime Translation).
Implementation:
The group parameter must name a GROUP that begins the same as the TranslatorGroup structure declared in ABUTIL.INC:
TranslatorGroup GROUP,TYPE
Number USHORT
END
When you declare a translation group, be sure to set the correct number of translation pairs in the GROUP. For example:
MyAppTranslator GROUP
Pairs USHORT(2) !2 translation pairs
PSTRING('&Insert') !begin 1st pair
PSTRING('&Agregar') ! end 1st pair
PSTRING('Insert a new Record') !begin 2nd pair
PSTRING('Agregar un nuevo Registro') ! end 2nd pair
END
The TranslatorClass uses whole word, case sensitive matching to search for text. For example, 'Insert' does not match '&Insert' or 'INSERT' or 'Insert a new Record.'
The Init method uses the AddTranslation method to add the translation pairs declared in ABUTIL.TRN to the translation process.
The various “Translate” methods apply the translation pairs.
Example:
MyTranslations GROUP !declare local translations
Pairs USHORT(4) !4 translations pairs
PSTRING('&Sound') ! item 1 text
PSTRING('&xSoundx') ! item 1 replacement text
PSTRING('&Volume') ! item 2 text
PSTRING('&xVolumex') ! item 2 replacement text
PSTRING('Preferences') ! item 3 text
PSTRING('xPreferencesx')! item 3 replacement text
PSTRING('OK') ! item 4 text
PSTRING('xOKx') ! item 4 replacement text
END
Translator TranslatorClass !declare Translator object
CODE
Translator.Init !initialize Translator object
!add default translation pairs
Translator.AddTranslation(MyTranslations) !add local translation pairs
OPEN(MyWindow)
Translator.TranslateWindow !translate all window controls
! and window titlebar
See Also: Init, TranslateControl, TranslatedControls, TranslateString, TranslateWindow