Page 1 of 1

TCalendarPicker

Posted: Thu Aug 08, 2019 9:58 am
by Malcolm
Is it possible to translate this component's Month and Day names?

Or are you planning to create Tsi* versions of some or all of the VCL 'Windows 10' components?

At this time it is the TCalendarPicker I would like to be able to translate.

Malcolm

Posted: Thu Aug 08, 2019 1:16 pm
by isiticov
Hello,

Unfortunately, Embarcadero developers hard-coded this control to use ONLY locale strings by USER_LOCALE. We will try to find how to workaround this or will try to find a way to translate these elements with code.

Posted: Thu Aug 08, 2019 7:30 pm
by Malcolm
Ah, so if the user is using the USER_LOCALE of their language, it will be OK for them. That may be OK for my purposes.

Re:

Posted: Tue May 05, 2020 12:07 pm
by Massimo
isiticov wrote: Thu Aug 08, 2019 1:16 pm Hello,

Unfortunately, Embarcadero developers hard-coded this control to use ONLY locale strings by USER_LOCALE. We will try to find how to workaround this or will try to find a way to translate these elements with code.
Hello,
I am interested in translating the TCalendarPicker component..any news about this?

Regards.

Massimo.

Re: TCalendarPicker

Posted: Wed May 06, 2020 3:37 am
by isiticov
Hello,

You can use the following events:
TCalendarPicker.OnCalendarDrawMonthItem
TCalendarPicker.OnCalendarDrawYearItem
TCalendarPicker.CalendarHeaderInfo.OnDrawDayOfWeek

to modify the text displayed in TCalendarPicker through DrawParams.Text and Text variables. Unfortunately for the header of TCalendarPicker you would need to handle the OnDrawHeader event and re-paint it completely.
Note: remember that you will need to "know" what is current user's locale and how it is related to the languages in your application in order to be able to get the translated text.
Note #2: as these elements initially displayed in user's language I would recommend to leave them as they are.
Below is a sample code for automatic translation using the TCalendarPicker.OnCalendarDrawMonthItem and TCalendarPicker.CalendarHeaderInfo.OnDrawDayOfWeek events:

Code: Select all

procedure TForm4.CalendarPicker1CalendarDrawMonthItem(Sender: TObject;
  DrawParams: TDrawViewInfoParams; CalendarViewViewInfo: TCellItemViewInfo);
var
   S: string;
begin
  if siLangDispatcher1.ActiveLanguage <> 1 then
  begin
    if siLangDispatcher1.TranslationMemory(DrawParams.Text, siLangDispatcher1.Language, S) then
      DrawParams.Text := S;
  end;
end;

procedure TForm4.HeaderInfoDrawDayOfWeek(Sender: TObject;
  DrawParams: TDrawParams; DayNumber: Integer; var Text: string);
var
   S: string;
begin
  if siLangDispatcher1.ActiveLanguage <> 1 then
  begin
    if siLangDispatcher1.TranslationMemory(Text, siLangDispatcher1.Language, S) then
      Text := S;
  end;
end;
This code assumes that running user's locale is the same as first language in dispatcher (Russian in my case) and Dispatcher's TranslationMemoryOption.Active property is True. And Strings property of TsiLang is filled with translations for days of week and month names:

Image

Re: TCalendarPicker

Posted: Thu May 07, 2020 2:45 pm
by Massimo
Hello,
thank you for your help.
I will try your suggestions.

Regards.

Massimo.