Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsupport for non-english resourcestrings, no need to restart an app after change of language, support for build under FMX #146
Conversation
…rcestrings, build under FMX - added FMXAPP directive to be able to build under FireMonkey -added support for non-english resourcestrings -added support for changing on the fly without closing an application
@@ -1907,9 +1931,10 @@ procedure TLanguageFile.Translate(var English: string); | |||
// case-sensitive (same as standard gettext) | |||
var result: string; | |||
begin | |||
result := FindMessage(Hash32( | |||
//resourcestrings may be not in English |
synopse
Oct 29, 2018
Owner
this comment (and below) is a bit confusing for sure -> need to delete old code, and fix comments
i: PtrInt; | ||
begin | ||
result := true; | ||
if (PtrInt(lpszType)<>PtrInt(RT_STRING)) then exit; | ||
i := (PtrInt(lpszName)-1)shl 4; | ||
for i := i to i+15 do begin // resourcestrings are stored by groups of 16 | ||
SetString(s,buf,LoadStringA(hInstance,i,buf,sizeof(buf))); | ||
SetString(s,buf,LoadStringW(hInstance,i,buf,sizeof(buf))); |
synopse
Oct 30, 2018
Owner
if s is a RawUTF8 you should NOT use UTF-16 input
use RawUnicodeToUtf8()
instead of SetString()
@@ -11303,7 +11303,7 @@ function Hash32(Data: pointer; Len: integer): cardinal; overload; | |||
// - has less colision than Adler32 for short strings | |||
// - is faster than CRC32 or Adler32, since use DQWord (128 bytes) aligned read | |||
// - uses RawByteString for binary content hashing, whatever the codepage is | |||
function Hash32(const Text: RawByteString): cardinal; overload; | |||
function Hash32(const Text: RawUTF8): cardinal; overload; |
synopse
Oct 29, 2018
Owner
not acceptable (it breaks existing user code), nor needed RawByteString as input allows to pass a RawUTF8
paustr
Oct 30, 2018
Author
I still need Hash32(const Text: RawUTF8), so it was written in mORMoti18n.
After SetCurrentLanguage(lngEnglish) method was called, all resourcestring need to be tranlated and method GetText was called. There is an implicit conversion from RawUTF8 to RawByteString and it causes loss of data. Please look at attached call stacks.
- function Hash32(const Text: RawByteString) was used
synopse
Oct 30, 2018
Owner
Don't trust the debugger. IMHO this is a debugger issue/bug/feature, which makes on its side a conversion when displaying the value in the IDE.
There is no actual conversion in the generated assembly when you assign a RawUTF8 to a RawByteString (use Alt-F2 to see it).
paustr
Oct 30, 2018
Author
But Hash32(const Text: RawByteString) called inside TLanguageFile.Translate(var English: string) returns result which is not equal to the hash saved in .messages file and so that TLanguage.FindMessage returns an empty string.
When I use Hash32(const Text: RawUTF8) both for writing strings to .messages file (inside ExtractAllResources) and inside TLanguageFile.Translate method I'm getting the same results.
I have an application, which default langage is polish and all it's text are in polish. |
Please see my review above, to make some needed corrections in your branch, then try again the pull request. |
Sample application
https://github.com/paustr/multiLangApp