[RichViewActions][Example] How to choose default UI language

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 14727
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[RichViewActions][Example] How to choose default UI language

Post by Sergey Tkachenko » Wed Aug 21, 2019 8:32 am

User interface of RichViewActions is available in many languages.
The code below explains how to choose the default UI language depending on the Windows settings.

Code: Select all

function GetSystemLanguage(var Language, Region: String): Boolean;
var
  Buf:    String;
  Len:    Integer;
begin
  // Locale name format: Language[-[Script-]Region]
  Result := False;
  SetLength(Buf, LOCALE_NAME_MAX_LENGTH);
  Len := GetUserDefaultLocaleName(PChar(Buf), LOCALE_NAME_MAX_LENGTH);
  if Len = 0 then
    exit;
  SetLength(Buf, Len-1);
  Len := Pos('-', Buf);
  if Len > 0 then
  begin
    Language := Copy(Buf, 1, Len-1);
    Region   := Copy(Buf, Len+1, MaxInt);
  end
  else
  begin
    Language := Buf;
    Region   := '';
  end;
  if Region <> '' then
  begin
    Len := Pos('-', Region);
    if Len > 0 then
      Region := Copy(Region, 1, Len-1);
  end;
  Result := True;
end;

function GetDefaultRVALanguage: TRVALanguageName;
var
  Lan, Reg: String;
begin
  Result := 'English (US)';
  if not GetSystemLanguage(Lan, Reg) then
    exit;
  if Lan = 'be' then Result := 'Byelorussian'
  else if Lan = 'bg' then Result := 'Bulgarian'
  else if Lan = 'ca' then Result := 'Catalan'
  else if Lan = 'cs' then Result := 'Czech'
  else if Lan = 'da' then Result := 'Danish'
  else if Lan = 'de' then Result := 'German'
  else if Lan = 'es' then Result := 'Spanish'
  else if Lan = 'fa' then Result := 'Farsi'
  else if Lan = 'fi' then Result := 'Finnish'
  else if Lan = 'fr' then Result := 'French'
  else if Lan = 'hi' then Result := 'Hindi'    // only for D2009+ or TNT
  else if Lan = 'hy' then Result := 'Armenian' // only for D2009+ or TNT
  else if Lan = 'hu' then Result := 'Hungarian'
  else if Lan = 'it' then Result := 'Italian'
  else if Lan = 'ja' then Result := 'Japanese'
  else if Lan = 'ko' then Result := 'Korean'
  else if Lan = 'lt' then Result := 'Lithuanian'
  else if Lan = 'ms' then Result := 'Malay'
  else if Lan = 'nb' then Result := 'Norwegian'
  else if Lan = 'nl' then Result := 'Dutch (NL)'
  else if Lan = 'pl' then Result := 'Polish'
  else if Lan = 'pt' then
  begin
    if Reg = 'PT' then
      Result := 'Portuguese (Portuguese)'
    else
      Result := 'Portuguese (Brazilian)'
  end
  else if Lan = 'ro' then Result := 'Romanian'
  else if Lan = 'ru' then Result := 'Russian'
  else if Lan = 'sk' then Result := 'Slovak'
  else if Lan = 'sw' then Result := 'Swedish'
  // else if Lan = 'th' then Result := 'Thai' // not included by default
  else if Lan = 'tr' then Result := 'Turkish'
  else if Lan = 'uk' then Result := 'Ukrainian'
  else if Lan = 'zh' then
  begin
    if Reg = 'CN' then
      Result := 'Chinese (Simplified)'
    else
      Result := 'Chinese (Big5)'
  end;
end;
How to use:

Let we have a form that uses the actions and contains RVAControlPanel1: TRVAControlPanel
(normally, you should have a single TRVAControlPanel in your application, it becomes default).
When this form is created, assign:

Code: Select all

  RVAControlPanel1.Language := GetDefaultRVALanguage;
After that, call the code that applies the current language (containing the procedures like RVA_LocalizeForm, RVALocalizeRuler, etc.). In our ActionTest projects, this code is inside the Localize method of the main form.

Post Reply