Localizing format settings lazarus / 31-LCL ---------------------------------------------------------------------- wp · 2013-02-11 21:39 I am working at a multi-language project. I am using po files, the Translations and DefaultTranslator units, and mostly the translation is working fine. Now I came across the issue how to translate the FormatSettings, for example month and weekday names. OK, I could put them into the po files, but my feeling is that there must be an easier way. Can anybody give me a hint? ---------------------------------------------------------------------- BigChimp · 2013-02-13 07:41 IMO they should depend by default on current OS settings (locale). Perhaps they should be overridable by an application-specific locale setting. AFAIR, there is such a setting for decimal commas etc.... it would make sense to have this for locale/language too. Then again, I suspect this has not been implemented. Perhaps people like Avishai, who have been working on similar issues, can comment. ---------------------------------------------------------------------- Avishai · 2013-02-13 10:39 It seems to me that it is already working.  When I log in to my English account and use TCalendar, I get English Month and Day names.  When I log in to my Hebrew account, I get Hebrew names.  So the system seem to be there but I haven't looked in to it.  Of course TCalendar is junk and I don't use it. ---------------------------------------------------------------------- Avishai · 2013-02-13 11:02 I just did a very small test and it worked.  If I logged in English I got English.  If I logged in Hebrew I got Hebrew.  I used 2 listBox to put the names. Code: [Select]Procedure Tform1.Formshow(Sender: Tobject); var   I: Integer; Begin   for I:= 1 to 12 do begin     ListBox1.Items.Add(SysToUTF8(LongMonthNames[I]));   End;   for I:= 1 to 7 do begin     ListBox2.Items.Add(SysToUTF8(LongDayNames[I]));   End; End; ---------------------------------------------------------------------- wp · 2013-02-13 11:37 I think too that this is working when going from a machine with English settings to a machine with German settings. But how can I change format settings at run-time, or at least at startup on the SAME machine without going into the machine's language settings? ---------------------------------------------------------------------- Avishai · 2013-02-13 11:53 I have had long discussions about this exact point.  Including adding property Language and property ParentLanguage to TApplication and all components that display or sort  text.  As far as I know, nothing has been done.  In my case the situation is even worse because I have to deal with LeftToRight and RightToLeft languages which means mirroring the TForm and all components.  Sorry, but I doubt that helps you very much. As for changing Application language without resetting System Locale, pretty much the response I got was "why would you ever do that???" ---------------------------------------------------------------------- wp · 2013-02-13 12:05 OK - looks like there is no "official" solution which I might have overlooked. Anyway, if somebody out there has the same issue, here is my translation unit which I use instead of the DefaultTranslator.pas and which adds some code inspired by the Lazarus IDE code. Switching of formatsettings occurs in UpdateFormatSettings which, however, works only for Windows. ---------------------------------------------------------------------- Avishai · 2013-02-13 12:44 It looks like you have found your solution, but I did want to point out that there is 'Var SysLocale' although it doesn't seem to be used for much. With your solution, how would you deal with having mixed languages on a Form?  I ask because I do this fairly often. ---------------------------------------------------------------------- marcov · 2013-02-13 14:56 Quote from: wp on February 13, 2013, 12:37:43 pmI think too that this is working when going from a machine with English settings to a machine with German settings. But how can I change format settings at run-time, or at least at startup on the SAME machine without going into the machine's language settings? Load defaultformatsettings with your own values? On Windows you can sysutils.getlocaleformatsettings to load the record with  LCID. I do this in Delphi in the .dpr before application object initialization. ---------------------------------------------------------------------- Avishai · 2013-02-13 15:26 Thanks Marcov, that works like a charm.  I don't think I would have found that on my own. ---------------------------------------------------------------------- Avishai · 2013-02-13 15:47 Wow! that solves a lot of problems.  I put a TMemo and a TListBox on a Form to test and it works perfectly. Code: [Select]const   Lang: Integer = $40D;  // Hebrew var   I: Integer;   LocaleInfo: TFormatSettings; Procedure Tform1.Button1click(Sender: Tobject); Begin   if Lang= $40D then     Lang:= $409   else     Lang:= $40D;   SysUtils.GetLocaleFormatSettings(Lang, LocaleInfo);   Memo1.Clear;   ListBox1.Clear;   Memo1.Lines.Add(IntToStr(Lang));   Memo1.Lines.Add(LocaleInfo.ShortDateFormat);   for I:= 1 to 12 do begin     ListBox1.Items.Add(SysToUTF8(LocaleInfo.LongMonthNames[I]));   End; End; ---------------------------------------------------------------------- wp · 2013-02-13 15:49 QuoteOn Windows you can sysutils.getlocaleformatsettings to load the record with  LCIDThat's what I am doing in the posted unit. But how about Linux?