Recent

Author Topic: Application.BiDiMode - should be based on application or system language?  (Read 6357 times)

dezlov

  • New Member
  • *
  • Posts: 13
Users of my applications started to report "a bug", where GUI is displayed in RightToLeft mode while the interface was in English (or any other non-RTL language).

Initially, I did not consider this to be a bug, so I kept suggesting users to change their system locale to non-RTL language. However, the more I thought about it the more it seemed like a bug. Now, I am almost convinced that it is plain wrong to use system locale to determine BiDiMode of an application, especially when BiDiMode of system locale and application's language are different.

Few examples to demonstrate:
  • System=Hebrew & Application=English => Application.BidiMode=bdRightToLeft (English in RTL)
  • System=English & Application=Hebrew => Application.BidiMode=bdLeftToRight (Hebrew in LTR)

This is automatically applied by LCL in TApplication.Create, at initialization section of Forms.pp unit:
Code: [Select]
  {$ifndef wince}// remove ifdef when gettext is fixed
  LCLGetLanguageIDs(LangDefault, LangFallback);
  if LangDefault <> '' then
    FBidiMode := Direction(LangDefault)
  else
    FBidiMode := Direction(LangFallback);
  {$else}
    FBidiMode := bdLeftToRight;
  {$endif}

I have also found a Bug Report #0022044: Wrong Initial value for Application.BidiMode
http://bugs.freepascal.org/view.php?id=22044

I would like to get opinions of users, application developers and Lazarus developers:
  • Can we disable/remove/move setting of Application.BidiMode based on system language in LCL?
  • Should Application.BidiMode be always initialized to bdLeftToRight by default?
  • Should Application.BidiMode be a part of Project Settings?
  • Should setting appropriate BidiMode be a responsibility of the developer of each application?
  • Should i18n/l10n procedures be able to automatically set Application.BidiMode according the loaded language?


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
We would need a maintainer for BiDi related stuff.
Zaher, would you be the maintainer?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
@JuhaManninen
You know, I sent many patches that accepted the past for bidimode, so i feel i am already maintaining it, but if the problem conflicted with other opinions , for that we need who judge for it.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
You know, I sent many patches that accepted the past for bidimode, so i feel i am already maintaining it, but if the problem conflicted with other opinions , for that we need who judge for it.

Yes, I know your work in this area. Thanks about it.
Maintainer is the person who judges cases with conflicting opinions. I think you could take that role more. None of Lazarus core developers uses RTL language natively. It means there is not enough knowledge or understanding for BiDi issues, and not even motivation for it because everybody basically "scratches his own itch". The "itch" for BiDi comes with RTL languages.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Ok, i will start with this bug, and i will send a patch for it in the bug trucker, it is one line btw.

dezlov

  • New Member
  • *
  • Posts: 13
So what's the plan?

Shall we move that BidiMode setting code out of TApplication.Create and into a separate method, e.g. TApplication.ApplySystemBiDiMode.

Code: [Select]
procedure TApplication.ApplySystemBidiMode;
var
  LangDefault, LangFallback: String;
begin
  {$ifndef wince} // remove ifdef when gettext is fixed
  LazGetLanguageIDs(LangDefault, LangFallback);
  if LangDefault <> '' then
    SetBidiMode(Direction(LangDefault))
  else
    SetBidiMode(Direction(LangFallback));
  {$endif}
end;

Application developers can then call this method if they wish to apply system's BiDIMode.

While in TApplication.Create just set the default:

Code: [Select]
const
  DefaultApplicationBiDiMode: TBiDiMode = bdLeftToRight;

constructor TApplication.Create;
begin
  ...
  FBidiMode := DefaultApplicationBiDiMode;
  ...
end;

Edit: Patch attached in http://bugs.freepascal.org/view.php?id=22044
« Last Edit: June 14, 2015, 01:57:21 pm by dezlov »

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
I think we don't not need DefaultApplicationBiDiMode because developer can set it in the project lpr before application.initialize
Code: [Select]
    Application.BidiMode := bdLeftToRight;
    Application.Initialize;

but for ApplySystemBidiMode i am not sure

but if we keep it in the application.create but change the fallback language to default bidimode (LeftToRight) not take it from LangFallback

Code: [Select]
  LazGetLanguageIDs(LangDefault, LangFallback);
  if LangDefault <> '' then
    FBidiMode := Direction(LangDefault)
  else
    FBidiMode := bdLeftToRight;

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
This not work, ignore
Code: [Select]
  LazGetLanguageIDs(LangDefault, LangFallback);
  if LangDefault <> '' then
    FBidiMode := Direction(LangDefault)
  else
    FBidiMode := bdLeftToRight;

We need to fix Lazarus IDE too when choose RightToLeft Language

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Choosing Right to left depend on Developer
1 - Application is English (default)
2 - Application is RTL

    Application.BidiMode := bdLeftToRight;
    Application.Initialize;

3 - Application is multi language, so RTL should take it from the language that choosed from the user of that application, not from the system
    developer can choose the language at first time runing from the system, so ApplySystemBidiMode  not useful here.
« Last Edit: June 14, 2015, 04:08:50 pm by Zaher »

 

TinyPortal © 2005-2018