【发布时间】:2010-10-01 13:59:08
【问题描述】:
我正在使用标准的 Delphi 常量 DayMonday 等,我想将它们转换为本地化字符串(例如“Lundi”)。是否有一个简单的 RTL 或 VCL 调用?
【问题讨论】:
-
顺便提个很好的问题,我必须查找详细信息,但这是可能的 ;-)。
我正在使用标准的 Delphi 常量 DayMonday 等,我想将它们转换为本地化字符串(例如“Lundi”)。是否有一个简单的 RTL 或 VCL 调用?
【问题讨论】:
您可以通过以下方式获得不同的区域设置:
var
fs : TFormatSettings;
x : string;
begin
GetLocaleFormatSettings(GetThreadlocale, fs);
x:= FormatDateTime('%mmmm', Now, fs);
// etc..
end;
GetThreadLocale 提供当前的 LCID,但您可以自己使用其他数字。
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;
有关完整列表,另请参阅 http://www.microsoft.com/globaldev/reference/lcid-all.mspx。
您甚至可以自己更改格式设置以创建真正精美的结果。
【讨论】:
我以为我找到了一种简单的“当前语言环境”方法。
system.pas 中定义了全局数组 LongDayNames[] 和 ShortDayNames[]
所以..
Label.Text = LongDayName[DayMonday];
例如应该可以工作。 除了返回“星期日”。这是因为 Delphi 内部支持两天编号方案,DayMonday 是 ISO8601 常量 1,而 LongDayName 数组预计星期日是一周的第一天。 C++Builder 进一步混淆了事情,因为字符串数组从零开始,而不是一。
【讨论】:
你可以这样做:
var d1:string;
// 法语:
case dayofweek(cxScheduler1.SelStart) of
1:d1:='Dimanche';
2:d1:='Lundi';
3:d1:='Mardi';
4:d1:='Mercredi';
5:d1:='Jeudi';
6:d1:='vendredi';
7:d1:='Samedi';
end;
【讨论】: