Recent

Author Topic: Add 'Language' property to Controls with Text?  (Read 58843 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #60 on: September 01, 2012, 10:44:42 am »
Thanks BigChimp, I always look forward to hearing your views on such things as this.

Each OS supported Language already has a numeric value (at least in Windows and I assume other OS's).  So it seems to me that a simple (but long) case statement would work to select a sort method.  That method could then be used by any control that needs to sort a list.  The one exception that I can think of is SortNumeric, but that would be easy to add to the case statement (LangNumeric).  I've experimented with this approach and it seems to work, but it's a very limited experiment because I don't know the correct Sort Order for many languages.  Lazarus has a truly global user base.  If we couldn't find some code that was already written that could be translated to Lazarus/FPC, I think it would not take long to collect Sort Methods from the Lazarus community to plug in to such a case statement.

And there's also the issue of activating the correct Keyboard.  I do these things now, switch Keyboard and Sort Order on a control by control basis.  But it took a lot of work and research, trial and error to get to this point and I'm still working on it.  I know I'm not the only one that has to deal with this and I can imagine other people trying to figure this out and reinvent this same wheel.

I would love to get a chance to look at how other programming environments approach this.  It's hard for me to believe that this isn't being handled in some way. 

For Lazarus ListBox, ComboBox... Sorted:= true is a "one trick pony" :)  And the worst part is that, if it is sorting non-English, you may get different results for each control.  I know this is true for Hebrew.  In Hebrew, ComboBox gives a different result for the same list depending on how many times you sort it :(

I took a look at Win32 CompareString but I haven't figured out how to use it yet.  I tried Lazarus/FPC CompareStr, but it Sorted 'ABC abc'.  That wouldn't work for me.  At least TStringList.CaseSensitive gives 'aA bB cC'.

I haven't posted anything to BugTracker yet because I wanted to get some input from other people to see how they feel about it.  It's been a mix.  The developers have a lot of things to work on so adding something to that list doesn't seem like the best thing just yet.  If and when we can come up with a coherent plan/design, then maybe we could present it to them.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #61 on: September 07, 2012, 07:35:24 pm »
I finally got a chance to take a look at VB.  It was a very short look so my impressions may be wrong.  But it looked like the Language Property was only at the Form Level.  That was disappointing.  I also didn't get a chance to see how it worked, but it didn't seem to activate the Language Keyboard as I had hoped.  Maybe there's a setting that I didn't see.

VB had no problem sorting Hebrew or English correctly regardless of what Language was set, but I can't say for other Languages.

I did get one major surprise.  VB has the Properties RightToLeft and RightToLeftLayout.  If both are set to TRUE, the Form and Canvas are Mirrored to make a True RightToLeft Form at Design-Time.  Left becomes Right and Right become Left.  So when you say Left:= 10, it means 10 from the Right.  This makes designing a RightToLeft Form just as easy as designing a LeftToRight Form without the huge amount a extra code and time needed finding workarounds in Lazarus.  Now I understand why there are so few Middle-Eastern and North Africans using Lazarus.

I have the code to Mirror the Forms and other controls, but it only works at Run-Time and only with Themes turned OFF.  When Themes are ON, TCanvas becomes corrupted and unusable.  There is something wrong with the way Lazarus handles Themes.  With the method I use, you have to design a LeftToRight Form and see it RightToLeft only at Run-Time.  If anyone wants the code, let me know.  I'll be happy to share and explain some of the strange workarounds that I have discovered.
« Last Edit: September 07, 2012, 07:40:22 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add 'Language' property to Controls with Text?
« Reply #62 on: September 07, 2012, 08:07:30 pm »
I did get one major surprise.  VB has the Properties RightToLeft and RightToLeftLayout.  If both are set to TRUE, the Form and Canvas are Mirrored to make a True RightToLeft Form at Design-Time.  Left becomes Right and Right become Left.  So when you say Left:= 10, it means 10 from the Right.  This makes designing a RightToLeft Form just as easy as designing a LeftToRight Form without the huge amount a extra code and time needed finding workarounds in Lazarus.  Now I understand why there are so few Middle-Eastern and North Africans using Lazarus.

In Apple's Xcode designer, you do this with a "constraint" (probably similar to VCL/LCL Constraints property). But they introduce "leading" and "trailing" properties, probably to avoid "reversing" the meaning of left and right the way MS did. I would guess that the same design could then be used with both left-to-right and right-to-left.

"Leading and trailing are similar to left and right, but they are more expressive because they automatically mirror the constraint in a right-to-left environment."

I take that to mean that "leading" is the space to the left of the text starting point in l-to-r and the space to the right of the text starting point in r-to-l.

Perhaps what you need in the form designer could be handled by an expanded Constraints property.

More info here:

http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/OSX_Technology_Overview/CocoaApplicationLayer/CocoaApplicationLayer.html#//apple_ref/doc/uid/TP40001067-CH274-SW20

Thanks.

-Phil

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Add 'Language' property to Controls with Text?
« Reply #63 on: September 07, 2012, 08:13:50 pm »
I did get one major surprise.  VB has the Properties RightToLeft and RightToLeftLayout.  If both are set to TRUE, the Form and Canvas are Mirrored to make a True RightToLeft Form at Design-Time.  Left becomes Right and Right become Left.  So when you say Left:= 10, it means 10 from the Right.  This makes designing a RightToLeft Form just as easy as designing a LeftToRight Form without the huge amount a extra code and time needed finding workarounds in Lazarus. 

As I said, you might want to look into how the Mono framework - the open source variant of the Microsoft CLR - handles this. On Windows, it should support RightToLeft etc as well... perhaps there's interesting hints in there....
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #64 on: September 07, 2012, 08:19:26 pm »
Thanks guys.  I'll look into both.  I just glanced at the Apple page.  It looks interesting.  I wasn't sure Apple even had Mirroring.  I was told that there was no need in Apple, but you can hear anything.  :)

As for Mono, I'm embarrassed to say I had never heard of it.  :-[  That's one of the really great things about being in a community like this.  You get to learn about all sorts of things you might never know about otherwise.
Lazarus Trunk / fpc 2.6.2 / Win32

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add 'Language' property to Controls with Text?
« Reply #65 on: September 07, 2012, 08:20:43 pm »
As I said, you might want to look into how the Mono framework - the open source variant of the Microsoft CLR - handles this. On Windows, it should support RightToLeft etc as well... perhaps there's interesting hints in there....

What's he talking about are properties in WinForms forms. Mono's WinForms support is deprecated, I believe, and most certainly _not_ cross-platform.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.righttoleftlayout.aspx

I'm not sure what the state of MonoDevelop's form designer is for WinForms.

Thanks.

-Phil

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add 'Language' property to Controls with Text?
« Reply #66 on: September 07, 2012, 08:31:29 pm »
As for Mono, I'm embarrassed to say I had never heard of it.  :-[  That's one of the really great things about being in a community like this.  You get to learn about all sorts of things you might never know about otherwise.

A bit of Mono info from Laz wiki:

http://wiki.lazarus.freepascal.org/Using_Pascal_Libraries_with_.NET_and_Mono

Two companies that have had quite a bit of success in utilizing Mono are Xamarin (http://xamarin.com) and RemObjects (remobjects.com). However, their interest (and success) is primarily due to a focus on mobile, particularly iOS (see RemObjects news). Mono no longer has corporate sponsorship (Novell), so I'm not sure where Mono as cross-platform _desktop_ tool will end up.

Thanks.

-Phil

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #67 on: September 07, 2012, 08:55:33 pm »
I guess I should say that I am not looking for a different programming environment.  My only reason for looking at the others is to see 'how' and 'if' they support Human Languages.  Lazarus isn't doing a very good job in that area yet and I would like to be able to help make it better.  I have some ideas, but they aren't fully developed ideas yet.

The big hangup right now for RightToLeft is Themes and TCanvas.  If that can be fixed, I already have the code to Mirror controls at design-time.  I just can't use it because all TCanvases turn permanently black.

I also want to see if I can find out how VB is doing Sorts and if it can be correct without regard to Language.  It worked for Hebrew and English so...
Lazarus Trunk / fpc 2.6.2 / Win32

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add 'Language' property to Controls with Text?
« Reply #68 on: September 07, 2012, 09:39:47 pm »
If that can be fixed, I already have the code to Mirror controls at design-time.  I just can't use it because all TCanvases turn permanently black.

Not sure what that second sentence means. At design time? At runtime?

Thanks.

-Phil

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Add 'Language' property to Controls with Text?
« Reply #69 on: September 07, 2012, 09:41:45 pm »
OK I've been following this thread on and off and I'm not sure if I remember correctly but, I disagree in extending all the components (ee all Tcontrol descentants) with a language property to allow for localization that would be redundant as it only needs a single variable and all components should use the same language regardless eg you can't have a grid in english and the tree next to it in arabic it makes no sense at all its an all or nothing deal in my opinion.

So either introduce a new global variable eg localization : TLocalization; where you can have what ever properties you need or introduce it in an existing global variable eg screen, Application etc with application being the most obvious choice.

As for Delphi, D2007 that I have, it uses resource dlls and the system locale info to decide which dll to load when it starts up. after that the only way to change the language is to access the module linked list that any application keeps in memory to track which modules are loaded find the module record of the application (Module.instance = HInstance) and replace module.ResInstance with the newly loaded dll instance, cleaning up as required of course.

I do not think that has changed in newer version of delphi as well.

If it was up to me I would use something similar to a resource dll for 2 reasons
1) I do not want any of my end user to mess around with the translation with out my permission (sharing the translation tool to them) that would make support a nightmare. This can be achieved by encrypting the translation files as well.
2) localization is more than a simple string translation it has to support control positioning (I might have to group controls differently to be closer to official documents for example) and other properties as well eg. it would be silly to show an English interface on a right to left environment so this has to be changed to left to right as well regardless of the operating system's locale.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #70 on: September 07, 2012, 09:46:42 pm »
@Phil.  Yes, at Run-Time.  It isn't mirrored at Design-Time or it would be black then too.  I've tried.  :)  Here's a screenshot of a form with a PageControl and some labels with themes ON.
Lazarus Trunk / fpc 2.6.2 / Win32

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Add 'Language' property to Controls with Text?
« Reply #71 on: September 07, 2012, 09:49:53 pm »
I also want to see if I can find out how VB is doing Sorts and if it can be correct without regard to Language.  It worked for Hebrew and English so...

VB doesn't sort or rather doesn't compare strings it uses the system CompareString which does a linguistic compare.

Yes, at Run-Time.  It isn't mirrored at Design-Time or it would be black then too.  I've tried.  :)  Here's a screenshot of a form with a PageControl and some labels with themes ON.

You do know that there is a example project for bidi in the examples\bidi directory right?
In it you can see how to change from left to right to right to left and vice versa and has a button to flip controls too, although I'm guessing that it does this by changing the controls position instead of relying in the bidi mode.
« Last Edit: September 07, 2012, 09:57:37 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add 'Language' property to Controls with Text?
« Reply #72 on: September 07, 2012, 09:52:21 pm »
@Phil.  Yes, at Run-Time.  It isn't mirrored at Design-Time or it would be black then too.  I've tried.  :)  Here's a screenshot of a form with a PageControl and some labels with themes ON.

Not sure what's going on there. It almost looks like the problem that a TCustomControl descendant can have if it leaves it's Color set to clDefault - in earlier versions of Laz, this was the same as clWindow, I believe, but it's now clBlack (or displays that way).

Might just be a coincidence...

Thanks.

-Phil

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #73 on: September 07, 2012, 10:00:15 pm »
@Phil.  No, I've done a huge amount of investigating.  Any and all TCanvas become corrupted.  If I add a few TEdits, as soon as I leave the first one, it's content is echoed to the Top-Right corner and is Mirrored.  Then other very strange things start happening as you move from TWinControl to TWinControl.  But the base Canvas stays black wherever it 'escapes' from the 'echo effect'.  You would really have to see it to understand it.  English written backwards isn't something I like to see on my forms.  :)
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Add 'Language' property to Controls with Text?
« Reply #74 on: September 07, 2012, 10:40:18 pm »
@taazz.

...with a language property to allow for localization that would be redundant as it only needs a single variable and all components should use the same language regardless eg you can't have a grid in english and the tree next to it in arabic it makes no sense at all its an all or nothing deal in my opinion.

How then can I write a Hebrew/English dictionary?  Or a Hebrew Form that requires English data as well such as 'Name, place of birth, date of birth...' for an International document?  I have many Forms that are at least bilingual.  'All or nothing' means that I can't write these programs.  Even your word processor likely support multilingual text.  My real name is אבישי.  Multilingual is simply a fact of life.  Fortunately, Lazarus is flexible enough to allow me to do this.  It just takes more work than it needs to.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018