[fpc-devel] Unicode resourcestrings

Daniël Mantione daniel.mantione at freepascal.org
Sun Mar 2 10:22:32 CET 2008



Op Sun, 2 Mar 2008, schreef Martin Schreiber:

> On Friday 29 February 2008 10.07:29 Dani=EBl Mantione wrote:
>>>
>>> Ideally from my point of view would be if the resourcestrings are stored
>>> in utf-8 if the unit is compiled with -Fcutf8 and decoded by utf8decode
>>> for widestring assignment on runtime independent of the system encoding.
>>
>> This has been discussed before. Automatic conversion to/from ansistrings
>> will always be to/from system encoding. If you want another encoding than
>> the system encoding you will have to do a manual conversion.
>>
>> For the compiler, a resourcestring has the same type as an ansistring, so
>> no distinction can be made between resourcestrings/ansistrings.
>>
> That means that the program must be compiled in the same system encoding =
as
> the target runs in order to get working resourcestrings? That would
> resourcestrings for i18n purposes render useless apart from utf-8-only or
> latin-1-only. utf-8-only is not possible for older existing installations.

In the traditional way of translating software (from the age when =

resourcestrings were invented) you encode your translation in the encoding =

of the target system. If you do a Dutch translation you could encoude your =

translation in ISO-8859-1 and if you do a Czech translation you could =

encoude the translation in ISO-8859-2.

A more modern approach is to encode all your translations in Unicode and =

convert them to the target encoding. I.e. UTF-8 to system encoding is what =

Lazarus does. There is utf8toansi function in the system unit for this =

purpose. But then you have to call utf82ansi on every resourcestring you =

access, similar to utf8decode if you use widestrings.

> The compiler does not know that the source is a resource string? But the
> compiler could know it, the information is available?

Language wise, resourcestrings are ansistring constants. So whenever you =

use a resourcestring identifier in your code, the compiler considers this =

an expression with type ansistring. Therefore, regarding typing they are =

equal.

Regarding code generation, there is a difference between ansistrings and =

resourcestrings, since with a resourcestring load, the compiler must look =

into the resourcestring tables to find the ansistring constant.

Dani=EBl


More information about the fpc-devel mailing list