Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get localised day names in Delphi?

I'm using standard Delphi constants DayMonday, etc and I want to convert them to localized strings (eg "Lundi"). Is there a simple RTL or VCL call for this?

like image 379
Roddy Avatar asked Jan 15 '09 12:01

Roddy


1 Answers

You can get different locale settings by:

var
  fs : TFormatSettings;
  x  : string;
begin
  GetLocaleFormatSettings(GetThreadlocale, fs);
  x:= FormatDateTime('%mmmm', Now, fs);
  // etc..
end;

GetThreadLocale gives the current LCID but you can use another number yourself.

TFormatSettings record:

TFormatSettings = record
  CurrencyFormat: Byte;
  NegCurrFormat: Byte;
  ThousandSeparator: Char;
  DecimalSeparator: Char;
  CurrencyDecimals: Byte;
  DateSeparator: Char;
  TimeSeparator: Char;
  ListSeparator: Char;
  CurrencyString: string;
  ShortDateFormat: string;
  LongDateFormat: string;
  TimeAMString: string;
  TimePMString: string;
  ShortTimeFormat: string;
  LongTimeFormat: string;
  ShortMonthNames: array[1..12] of string;
  LongMonthNames: array[1..12] of string;
  ShortDayNames: array[1..7] of string;
  LongDayNames: array[1..7] of string;
  TwoDigitYearCenturyWindow: Word;
end;

See also http://www.microsoft.com/globaldev/reference/lcid-all.mspx for a complete list.

You can even change the formatsettings yourself to create really fancy results.

like image 50
Toon Krijthe Avatar answered Oct 10 '22 20:10

Toon Krijthe