Recent

Author Topic: [CLOSED] Improvement of TApplication.IsRTLLang  (Read 1942 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[CLOSED] Improvement of TApplication.IsRTLLang
« on: August 27, 2023, 02:57:09 pm »
lcl/include/application.inc has
Code: Pascal  [Select][+][-]
  1. function TApplication.IsRTLLang(const ALang: String): Boolean;
  2. var
  3.  lng : String;
  4.  p   : word;
  5.  
  6.   function sep_pos : word; inline;
  7.   begin
  8.     Result := Pos('-', lng);
  9.     if Result = 0 then
  10.       Result := Pos('_', lng);
  11.   end;
  12.  
  13. begin
  14.   lng    := LowerCase(ALang);
  15.   p      := sep_pos;
  16.   if p > 0 then
  17.     lng := copy(lng, 1, p-1);
  18.  
  19.   Result := (lng = 'ar') or // Arabic
  20.             (lng = 'he') or // Hebrew
  21.             (lng = 'yi') or // Yiddish
  22.  
  23.             // The languages bellow usually use arabic as the language name
  24.             (lng = 'dv') or
  25.             (lng = 'ps') or
  26.             (lng = 'az') or
  27.             (lng = 'fa') or
  28.             (lng = 'ks') or
  29.             (lng = 'ku') or
  30.             (lng = 'pa') or
  31.             (lng = 'sd') or
  32.             (lng = 'tk') or
  33.             (lng = 'ug') or
  34.             (lng = 'ur') { or
  35.  
  36.               Not sure about the following languages ...
  37.               They do not have 2 letters ISO standard are they in use ?
  38.             (lng = 'jpr') or
  39.             (lng = 'syr') or
  40.             (lng = 'nqo') or
  41.             (lng = 'jrb')
  42.             }
  43.             ;
  44. end;

In order to match the result of the "Pos" function and the parameter of the "copy" function, variable "p" and nested function "sep_pos" have been changed from word to sizeint.
After that, the line "lng := copy(lng, 1, p-1);" has been replaced with "SetLength(lng, p-1);".
The modified function looks like this:
Code: Pascal  [Select][+][-]
  1. function TApplication.IsRTLLang(const ALang: String): Boolean;
  2. var
  3.  lng : String;
  4.  p   : SizeInt;
  5.  
  6.   function sep_pos : SizeInt; inline;
  7.   begin
  8.     Result := Pos('-', lng);
  9.     if Result = 0 then
  10.       Result := Pos('_', lng);
  11.   end;
  12.  
  13. begin
  14.   lng    := LowerCase(ALang);
  15.   p      := sep_pos;
  16.   if p > 0 then
  17.     SetLength(lng, p-1);
  18.  
  19.   Result := (lng = 'ar') or // Arabic
  20.             (lng = 'he') or // Hebrew
  21.             (lng = 'yi') or // Yiddish
  22.  
  23.             // The languages bellow usually use arabic as the language name
  24.             (lng = 'dv') or
  25.             (lng = 'ps') or
  26.             (lng = 'az') or
  27.             (lng = 'fa') or
  28.             (lng = 'ks') or
  29.             (lng = 'ku') or
  30.             (lng = 'pa') or
  31.             (lng = 'sd') or
  32.             (lng = 'tk') or
  33.             (lng = 'ug') or
  34.             (lng = 'ur') { or
  35.  
  36.               Not sure about the following languages ...
  37.               They do not have 2 letters ISO standard are they in use ?
  38.             (lng = 'jpr') or
  39.             (lng = 'syr') or
  40.             (lng = 'nqo') or
  41.             (lng = 'jrb')
  42.             }
  43.             ;
  44. end;

Here is the patch.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/include/application.inc b/lcl/include/application.inc
  2. index 10abe008b0..4f3cfcfc9f 100644
  3. --- a/lcl/include/application.inc
  4. +++ b/lcl/include/application.inc
  5. @@ -2464,9 +2464,9 @@ end;
  6.  function TApplication.IsRTLLang(const ALang: String): Boolean;
  7.  var
  8.   lng : String;
  9. - p   : word;
  10. + p   : SizeInt;
  11.  
  12. -  function sep_pos : word; inline;
  13. +  function sep_pos : SizeInt; inline;
  14.    begin
  15.      Result := Pos('-', lng);
  16.      if Result = 0 then
  17. @@ -2477,7 +2477,7 @@ begin
  18.    lng    := LowerCase(ALang);
  19.    p      := sep_pos;
  20.    if p > 0 then
  21. -    lng := copy(lng, 1, p-1);
  22. +    SetLength(lng, p-1);
  23.  
  24.    Result := (lng = 'ar') or // Arabic
  25.              (lng = 'he') or // Hebrew
« Last Edit: August 28, 2023, 10:09:12 am by lagprogramming »

AlexTP

  • Hero Member
  • *****
  • Posts: 2480
    • UVviewsoft

 

TinyPortal © 2005-2018