gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locale usage


From: Michael Scheibler
Subject: Re: Locale usage
Date: Mon, 30 Apr 2001 08:20:51 +0200

From: "Richard Frith-Macdonald" <address@hidden>
>
> While I have just committed a hack to use NSDecimalSeparator in strings,
> I suspect that
> what I've done is wrong.
>
> Currently, GNUstep sets the current locale in the libc code to the
> locale specified by
> the environment variables using setlocale().  This makes libc functions
> like printf
> produce output according to the values specified in the environment.
> Since the stringWithFormat: routines use sprintf for formatting floating
> point values,
> this means that everything gets formatted the way the environment
> variables specify.
> My hack attempts to rewrite the output of sprintf to conform to the
> formatting
> specified in the locale dictionary.
>
>
> Having run some tests on MacOS-X, I think this is wrong.
>
> It looks to me as if the 'C' or 'POSIX' locale should always be used
> except for methods
> like -
>
> localizedStringWithFormat:
>    (use [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
> for formatting)
> initWithFormat:locale:
>    (use supplied locale dictionary for formattting)
>
>
> So, I think that GNUstep should behave as follows -
>
> On startup, setlocale() to the environment variable supplied values, and
> read the
> locale to provide default values for the OpenStep locale dictionary.
> Then use setlocale() again to set the locale to the POSIX locale - so
> that this will
> be used as default.
>
> Thereafter, all non localised formatting, and in particular, all
> formatting done
> by standard libc functions, will be according to the POSIX locale.
> Perhaps the
> GSSetLocale() function should be removed, so use of the POSIX locale is
> forced?
>
> Localised methods where no dictionary is supplied, will use the values
> stored
> at startup.
>
> Localised methods with a dictionary supplied will use the formatting
> specified
> in the dictionary.
>
> Ideally, the code in GSFormat.m should be extended to handle floats
> directly
> rather than using sprintf() ... I think any rewriting of sprintf()
> output is
> going to be error prone and inefficient.
>
>
> Thoughts?
>

IMO it would be best not to rely on locale dependend functions like sprintf,
but to implement our own formatting routine while keeping the current locale
setting behaviour.
You never know when someone uses libc functions, so it wouldn't be enough
just to remove GSSetLocale(). This can lead to runtime errors when reading
from a file.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]