[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Locale usage
From: |
Richard Frith-Macdonald |
Subject: |
Locale usage |
Date: |
Sat, 28 Apr 2001 09:29:08 +0100 |
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?
- Locale usage,
Richard Frith-Macdonald <=