TLocalTranslations Class

Handles the translations that exist in the current copy of your application. The instance of it should be created at the beginning of the program’s functioning, before the user interface is shown.

Constructor

Format:

TLocalTranslations (const UnicodeString &TranslationsFolder,
  const TProgramVersion &ProgramVersion,
  TLocalTranslationGetFunc ApplyTranslationFunc,
  const std::vector  &BuiltInLanguages,
  const TLocalTranslation &DefaultTranslation,
  ptrdiff_t CallbackParam);
					
constructor Create(const TranslationsFolder: WideString;
  const ProgramVersion: TProgramVersion;
  ApplyTranslationFunc: TLocalTranslationGetFunc;
  const BuiltInLanguages: Array of TLanguage;
  const DefaultTranslation: TLocalTranslation); overload;
					

Parameters:

Note: The ApplyTranslationFunc function passed to the constructor will be immediately called just after the instance of the class is created. This is necessray to apply the active translation to the user interface after the program was launched.

However, if you want to create the instance of TLocalTranslations without simultaneous calling ApplyTranslationFunc (for example, if creating it globally, on the very early stage of the application launch), you may create the TLocalTranslations instance using the no-arguments constructor. Later, when the ApplyTranslationFunc will be available, just create TLocalTranslations with all necessary arguments and assign it to the early used variable.

GetActiveTranslation

Returns the information about the translation, which is currently active in your application.

Format:

TLocalTranslation GetActiveTranslation();
				
function GetActiveTranslation: TLocalTranslation;
				

Return value: Item of the type TLocalTranslation.

Parameters: None.

SetPreferredLanguage

Sets the passed language as preferred and remembers this choice. If, for changing the language, it is necessary to switch to another local translation and if one is available, then the ApplyTranslationFunc function passed through the constructor will be called.

Format:

void SetPreferredLanguage (const TLanguage &Language);
				
procedure SetPreferredLanguage(const Language: TLanguage);
				

Parameter: Item of the type TLanguage.

Return value: None.

GetPreferredLanguage

Returns the preferred language for using in the program's interface. The translation for this language is not necessarily available.

Format:

TLanguage GetPreferredLanguage ();
				
function GetPreferredLanguage: TLanguage;
				

Return value: Item of the type TLanguage.

Parameters: None.

By default, the preferred language is a system one, but the translation to it can be unavailable. To get the translation, which is guaranteed to exist and is currently active, call:

TLocalTranslations *LocalTranslations = new TLocalTranslations (...

TLocalTranslation Translation = LocalTranslations->GetBestLocalTranslation(
  LocalTranslations->GetPreferredLanguage());
				
var LocalTranslations: TLocalTranslations;
  Translation: TLocalTranslation;
...
Translation := LocalTranslations.GetBestLocalTranslation(
  LocalTranslations.GetPreferredLanguage);
				

GetBestLocalTranslation

Returns the most suitable local translation to the given language for the current program version.

Format:

TLocalTranslation GetBestLocalTranslation(const TLanguage &Language);
				
function GetBestLocalTranslation(
  const Language: TLanguage): TLocalTranslation;
				

Return value (TLocalTranslation): The most suitable local translation.

Parameter (TLanguage): Language for which you want to find the translation.

If the translation to the passed language is not found, the translation to the system language will be looked for. If such a translation is also not found, the default translation will be returned. (This is explained in the DefaultTranslation constructor parameter description.) To get the translation, which is guaranteed to exist and is currently active, call:

TLocalTranslations *LocalTranslations = new TLocalTranslations (...

TLocalTranslation Translation = LocalTranslations->GetBestLocalTranslation(
  LocalTranslations->GetPreferredLanguage());
				
var LocalTranslations: TLocalTranslations;
  Translation: TLocalTranslation;
...
Translation := LocalTranslations.GetBestLocalTranslation(
  LocalTranslations.GetPreferredLanguage);
				

GetAllBestLocalTranslations

Returns the local translations for all available languages. Each returned translation is the most suitable for its language and is the most recent translation version. Thus, the result of this function can be interpreted as the list of languages available for enabling in the program's interface.

Format:

std::vector <TLocalTranslation> GetAllBestLocalTranslations();
				
function GetAllBestLocalTranslations: TLocalTranslationArray;
				

Return value: Items set of the type TLocalTranslation.

Parameters: None.