Question

J'utilise les constantes standard Delphi DayMonday, etc. et je souhaite les convertir en chaînes localisées (par exemple, "Lundi"). Existe-t-il un simple appel RTL ou VCL pour cela?

Était-ce utile?

La solution 2

J'ai pensé que j'avais trouvé un moyen simple de définir les "paramètres régionaux en cours".

Il existe des tableaux globaux LongDayNames [] et ShortDayNames [] définis dans system.pas

Alors ..

  Label.Text = LongDayName[DayMonday];

devrait fonctionner, par exemple. Sauf qu'il renvoie "dimanche" . En effet, Delphi prend en charge en interne les schémas de numérotation sur deux jours et que DayMonday est une constante ISO8601 1, alors que le tableau LongDayName s'attend à ce que dimanche soit le premier jour de la semaine. C ++ Builder complique davantage les choses car le tableau de chaînes commence à zéro, pas à un.

Autres conseils

Vous pouvez obtenir différents paramètres régionaux en:

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

GetThreadLocale donne le LCID actuel mais vous pouvez utiliser un autre numéro vous-même.

Enregistrement TFormatSettings:

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;

Voir aussi http://www.microsoft.com/globaldev/reference/ lcid-all.mspx pour une liste complète.

Vous pouvez même modifier vous-même les formats de format pour créer des résultats vraiment fantaisistes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top