[SOLVED] Translation of month names to Hebrew lazarus / 31-LCL ---------------------------------------------------------------------- wp · 2013-12-17 23:31 Running this code on Windows Code: [Select]procedure TForm1.Button1Click(Sender: TObject); const   // http://msdn.microsoft.com/de-de/goglobal/bb964664.aspx   LCID_EN = $0409;   LCID_DE = $0407;   LCID_FR = $040C;   LCID_HE = $040D; var   s_EN, s_DE, s_FR, s_HE: String;   fs: TFormatSettings; begin   // Month name in English   GetLocaleFormatSettings(LCID_EN, fs);   s_EN := SysToUTF8(FormatDateTime('mmmm', Date, fs));   // Month name in German   GetLocaleFormatSettings(LCID_DE, fs);   s_DE := SysToUTF8(FormatDateTime('mmmm', Date, fs));   // Month name in French   GetLocaleFormatSettings(LCID_FR, fs);   s_FR := SysToUTF8(FormatDateTime('mmmm', Date, fs));   // Month name in Hebrew   GetLocaleFormatSettings(LCID_HE, fs);   s_HE := SysToUTF8(FormatDateTime('mmmm', Date, fs));   ShowMessage(Format(     'This month is'#13 +     '  %s (in English)'#13 +     '  %s (in German)'#13 +     '  %s (in French)'#13 +     '  %s (in Hebrew)', [     s_EN, s_DE, s_FR, s_HE   ])); end;      displays a messagebox with the current month in several languages. The Hebrew name, however, does not show Hebrew characters. Am I missing something, or is this a bug? ---------------------------------------------------------------------- Bart · 2013-12-17 23:45 Possible explanation: Hebrew characters are outside your current codepage. Hence SysToUTF8 will display "garbage". You might try the WideString API instead and the use Utf16ToUtf8. (And your current font needs to support displaying Hebrew characters as well.) Bart ---------------------------------------------------------------------- wp · 2013-12-17 23:53 Quotetry the WideString APIWhat do I have to do for that? ---------------------------------------------------------------------- kpeters58 · 2013-12-18 00:17 just to be sure: Hebrew language support is installed on the machine in question? ---------------------------------------------------------------------- Avishai · 2013-12-18 03:54 This is the code I use.  Note: Your "LCID_HE" and My "HE_IL" have the same definition, so just replace HE_IL with LCID_HE and it *should* work. Code: [Select]procedure FixHebShortDayNames; var   HebShortDayNames: TWeekNameArray = ('א','ב','ג','ד','ה','ו','ש'); begin   if SysLocale.DefaultLCID = HE_IL then     DefaultFormatSettings.ShortDayNames:= HebShortDayNames; end; function GetLongMonthNames(I: Integer): String; begin   Result:= AnsiToUTF8(FormatSettings.LongMonthNames[I]); end; function GetShortMonthNames(I: Integer): String; begin   Result:= AnsiToUTF8(FormatSettings.ShortMonthNames[I]); end; function GetLongDayNames(I: Integer): String; begin   Result:= AnsiToUTF8(FormatSettings.LongDayNames[I]); end; function GetShortDayNames(I: Integer): String; begin   Result:= AnsiToUTF8(FormatSettings.ShortDayNames[I]); end; function GetCurrencyString: String; begin   Result:= AnsiToUTF8(DefaultFormatSettings.CurrencyString); end; function GetHebFullDate(ADate: TDate): String; { 2013 ,יום ד 18 בדצמבר} var   CurSettings: TFormatSettings;   CurLang: Integer; begin   CurSettings:= FormatSettings;   CurLang:= SysLocale.PriLangID;   SysLocale.PriLangID:= HE_IL;   GetLocaleFormatSettings(SysLocale.PriLangID,FormatSettings);   Result:= AnsiToUTF8(FormatDateTime('ddd, d בMMMM, YYYY',ADate));   FormatSettings:= CurSettings;   SysLocale.PriLangID:= CurLang;   GetLocaleFormatSettings(SysLocale.PriLangID,FormatSettings); end; function GetHebLongDate(ADate: TDate): String; { 2013 יום רביעי 18 בדצמבר } var   CurSettings: TFormatSettings;   CurLang: Integer; begin   CurSettings:= FormatSettings;   CurLang:= SysLocale.PriLangID;   SysLocale.PriLangID:= HE_IL;   GetLocaleFormatSettings(SysLocale.PriLangID,FormatSettings);   Result:= AnsiToUTF8(FormatDateTime('dddd, d בMMMM, yyyy',ADate));   FormatSettings:= CurSettings;   SysLocale.PriLangID:= CurLang;   GetLocaleFormatSettings(SysLocale.PriLangID,FormatSettings); end; ---------------------------------------------------------------------- wp · 2013-12-18 08:58 @Avishai: same problem - as I expected because your code is essentially the same as mine. @kpeters58: that could be the reason. Unfortunately, I cannot test since I am using a German Windows 7 Professional, and language packs can only be installed for the Enterprise and Ultimate versions. Piece of crap! ---------------------------------------------------------------------- Avishai · 2013-12-18 09:04 wp, that doesn't sound right.  I use English Windows 7 Professional and I can install Language Packs.  Have you tried http://windows.microsoft.com/en-us/windows/language-packs#lptabs=win7 ---------------------------------------------------------------------- wp · 2013-12-18 09:16 Thanks for the link. But the edition required for Hebrew is marked as Ultimate or Enterprise... ---------------------------------------------------------------------- Avishai · 2013-12-18 09:21 I was able to install it on my system with no problem.  I'm trying to remember if I had to do anything special.  It was so long ago that I don't remember. ---------------------------------------------------------------------- CM630 · 2013-12-18 09:49 *WP, I am quite sure, that you do not have to install a language pack (if you mean a language interface pack), but to change the language for non-unicode programs, like shown in this video.+ Yet, if you do so, you will have problems with German, the umlauts will go kaputt. So, if I get things right, GetLocaleFormatSettings(LCID_DE, fs); returns the value as ASCII. If so, what what you have to is to use CPsomethingToUTF8... I suppose. Probably CP862toUTF8.I could offer you to add some other nonlatin language to you app- Russian, Bulgaria, Georgian... they should display monkeys, too. Edit: Exactly, your solution is: Code: [Select]uses ...LConvEncoding... . . s_HE := CP1255ToUTF8(FormatDateTime('mmmm', Date, fs)); . . But, you will have to do the same for German (s_DE := CP1252ToUTF8(FormatDateTime('mmmm', Date, fs)); ), French, etc. As you already mentioned, this is the Windows only solution. ---------------------------------------------------------------------- wp · 2013-12-18 11:57 Thank you, the CP1255ToUTF8 instead of SysToUTF8 did the trick. Of course, this leads to the next question: Is there a function which determines the code page from the LCID? ---------------------------------------------------------------------- wp · 2013-12-18 12:25 Ah, I found it: Code: [Select]uses   ... LConvEncoding, ... function GetLocaleStr(LID, LT: Longint; const Def: string): ShortString; // borrowed from SysUtils var   L: Integer;   Buf: array[0..255] of Char; begin   L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));   if L > 0 then     SetString(Result, @Buf[0], L - 1)   else     Result := Def; end; var   cp: String;   s_HE: String;   cp := 'cp'+GetLocaleStr(LCID_HE, LOCALE_IDEFAULTANSICODEPAGE, '');   s_HE := ConvertEncoding(FormatDateTime('mmmm', Date, fs), cp, EncodingUTF8); ---------------------------------------------------------------------- Avishai · 2013-12-18 14:46 wp, how is "fs" defined? ---------------------------------------------------------------------- wp · 2013-12-18 14:51 Sorry - it is defined in the first posting: fs is type TFormatSettings. ---------------------------------------------------------------------- Avishai · 2013-12-18 15:29 Sorry, I'm fighting an ear infection for the last couple of weeks and the antibiotics aren't helping.  The pain makes it hard to think or even comprehend what I'm reading. Thanks for pointing this problem out.  I was comfortable with my code but I see now that it has to be changed.  The only reason there hasn't been a problem is because anyone that has used my work is running a Hebrew enabled system.  With your code I should be able to fix it. ---------------------------------------------------------------------- wp · 2013-12-18 15:33 Hoping that you get well soon ---------------------------------------------------------------------- CM630 · 2013-12-19 07:26 Just to put an final point to the topic- if languages, other that Hebrew are uses, care shall be taken about capitalization. For example, if s_BG stands for Bulgarian, you should use:   s_BG := lowercase(ConvertEncoding(FormatDateTime('mmmm', Date, fs), cp, EncodingUTF8)); because Windows generates the first day with a capital letter, an they shall be written with a regular one. On the other hand, for English you should not use lowercase. ---------------------------------------------------------------------- wp · 2013-12-19 09:46 Is there a setting on capitalization somewhere in the formatsettings or similar? ---------------------------------------------------------------------- taazz · 2013-12-19 10:01 Care should be taken during the translation of the text not after and certainly not when the text is loaded. The library that handles the loading should not have any logic that has nothing to do with the loading.