Getting the Translation to the System Language on the Server

Let us imagine that the current system language is Russian. This means that the Russian-speaking user currently has only the options to choose either the English or the German interface language for Sample Program.

But the good thing is that, although the Russian language has not been pre-installed with Sample Program, it was added to the server by the volunteer translator after the release of Sample Program. This is why, although our app is displayed in English after the launch, we see the invitation in the system language (Russian) to enable the corresponding translation:



We may ensure that the Russian localization is available for Sample Program by visiting its LangsHelper account’s page: http://langshelper.com/DemoAccount.

The button from the above window is shown due to processing the event of the type TTranslationsEvent_ LanguageSwitchPossible in the LangsHelper event handling function of our app named EventFunc. The fact that the class of this type is passed to it after calling CheckForEvent means that there is an unofficial translation to a more suitable language for the current system on the server than the one currently active in our app.

See the corresponding fragment of the EventFunc below. The enabling invitation text for the button is taken from the event’s class function named GetOnSiteTranslation. We got this text from the server, not somewhere from our application’s resources:

static void EventFunc(const TTranslationsEvent *Event, ptrdiff_t OptionalParam)
{
...
const TTranslationsEvent_LanguageSwitchPossible *LanguageSwitchEvent =
  dynamic_cast <const TTranslationsEvent_LanguageSwitchPossible*> (Event);
if (LanguageSwitchEvent)	{
  // It is possible to switch to the more sutiable language by downloading
  // the translation from the site.
  ...	
  // Outputting the short invitation. It will be on the recommended
  // translation's language
  This->SysLangFoundButton.SetText(
    LanguageSwitchEvent->GetOnSiteTranslation().InvitationShort);	
  ...
  }
...
}
					
procedure TForm1.EventFunc(const Event: TTranslationsEvent);
var
  LanguageSwitchEvent: TTranslationsEvent_LanguageSwitchPossible;
begin  
  ...
  if Event is TTranslationsEvent_LanguageSwitchPossible then
  begin
    LanguageSwitchEvent := Event as TTranslationsEvent_LanguageSwitchPossible;
    // It is possible to switch to the more sutiable language by downloading
    // the translation from the site.
    ...	
    // Outputting the short invitation. It will be on the recommended
    // translation's language
    Button2.Caption := LanguageSwitchEvent.GetOnSiteTranslation.InvitationShort;
    ...	
  end
end;
					

Let us go further. If we click on the above invitation button, we will get the window in the system (Russian in this case) and English languages with the offer to enable this unofficial translation:



This dialog is shown by calling the LanguageSwitch function of the TTranslationsSiteInteraction class and passing the event’s class instance to it:

const TTranslationsEvent_LanguageSwitchPossible *LanguageSwitchEvent =
  dynamic_cast <const TTranslationsEvent_LanguageSwitchPossible*> (
    OccurredEvent.get());
if (LanguageSwitchEvent) {
  TLocalTranslation LocalTranslation;
  bool Result = TranslationsSiteInteraction->LanguageSwitch (
    LanguageSwitchEvent,
    LocalTranslation);
  if (Result) {
    // The new translation has been downloaded and applied
    ...
    }
  }
					
var
  LanguageSwitchEvent: TTranslationsEvent_LanguageSwitchPossible;
  LocalTranslation: TLocalTranslation;
...
if OccurredEvent is TTranslationsEvent_LanguageSwitchPossible then
  begin
    LanguageSwitchEvent :=
      OccurredEvent as TTranslationsEvent_LanguageSwitchPossible;
    Result := TranslationsSiteInteraction.LanguageSwitch (
      LanguageSwitchEvent,
      LocalTranslation);
    if Result then
    begin
      // The new translation has been downloaded and applied
      ...
    end
  end
					

Once we choose OK in the above dialog window, the Russian translation will be downloaded and enabled. Our program is in Russian now, which is the system language in our demonstration:


Next step: Rating the Translation