TCalendarPicker

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
Malcolm
Posts: 114
Joined: Tue Jan 21, 2003 5:18 pm
Location: Scotland

TCalendarPicker

Post 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
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post 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.
Best regards,
Igor Siticov.
Malcolm
Posts: 114
Joined: Tue Jan 21, 2003 5:18 pm
Location: Scotland

Post 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.
Massimo
Posts: 4
Joined: Tue May 05, 2020 10:10 am

Re:

Post 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.
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Re: TCalendarPicker

Post 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
Massimo
Posts: 4
Joined: Tue May 05, 2020 10:10 am

Re: TCalendarPicker

Post by Massimo »

Hello,
thank you for your help.
I will try your suggestions.

Regards.

Massimo.
Post Reply