[fpc-pascal] BoolToStr() with correct locale output

Michael Van Canneyt michael at freepascal.org
Fri Jun 26 13:32:53 CEST 2009



On Fri, 26 Jun 2009, Graeme Geldenhuys wrote:

> Hi,
>
> I'm busy translating our projects. fpGUI Toolkit uses it's own
> translation via .po files (similar to Lazarus projects). But now there
> are some output that is not being translated because it is output from
> the RTL. One such case is the output of BoolToStr().
>
> How am I supposed to translate that, or must I implement my own
> fpgBoolToStr() to fpGUI project?

No. The Boolean strings are exposed in from the sysutils unit,
see TrueBoolStr, FalseBoolStr. The first string in those arrays
is used. If there are no elements in those arrays, they are 
initialized with 'True' and 'False'.

So all you need to do is initialize them with the localized versions
prior to the first call of BoolToStr().

Michael.

>
> My default locale is en_ZA.UTF-8.  Normally if I change the LANG
> environment variable, my fpGUI based projects look for those language
> translation .po files and if none is found, it reverts to the default
> compiled locale (normally English, but other languages can be selected
> as default)
>
>
> ========  Console output ==================
> $ ./project1
> True
> False
>
> $ export LANG=af_ZA
>
> $ ./project1
> True
> False
>
> $ locale
> LANG=af_ZA
> LC_CTYPE="af_ZA"
> LC_NUMERIC="af_ZA"
> LC_TIME=en_DK.UTF-8
> LC_COLLATE="af_ZA"
> LC_MONETARY="af_ZA"
> LC_MESSAGES="af_ZA"
> LC_PAPER="af_ZA"
> LC_NAME="af_ZA"
> LC_ADDRESS="af_ZA"
> LC_TELEPHONE="af_ZA"
> LC_MEASUREMENT="af_ZA"
> LC_IDENTIFICATION="af_ZA"
> LC_ALL=
>
> ==========================
>
>
>
> =============  project1.pas  ===============
> program project1;
>
> {$mode objfpc}{$H+}
>
> uses
>  {$IFDEF UNIX}{$IFDEF UseCThreads}
>  cthreads,
>  {$ENDIF}{$ENDIF}
>  Classes, Sysutils;
>
> var
>  b: Boolean;
> begin
>  b := True;
>  writeln(BoolToStr(b, True));
>  b := False;
>  writeln(BoolToStr(b, True));
> end.
> ============================================
>
>
> Regards,
>  - Graeme -
>
> _______________________________________________________
> fpGUI - a cross-platform GUI toolkit using Free Pascal
> http://opensoft.homeip.net/fpgui/
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



More information about the fpc-pascal mailing list