Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

locale function - ideas on command format

56 views
Skip to first unread message

Brad Lanam

unread,
Aug 2, 2018, 4:47:46 PM8/2/18
to
I currently have:

bll-tecra:bll$ env LC_ALL=de_DE.UTF-8 rlwrap tclsh
% load [pwd]/locale.so
% locale all {}
de_DE.UTF-8
% locale get
decimal_point , thousands_sep . grouping 33 currency_symbol €
% locale all en_GB.UTF-8
en_GB.UTF-8
% locale get
decimal_point . thousands_sep , grouping 33 currency_symbol £
%

And yes, the call to setlocale with an empty string is required:

bll-tecra:bll$ env LC_ALL=de_DE.UTF-8 rlwrap tclsh
% load [pwd]/locale.so
% locale all -get
LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C
%

I currently have:
locale get ; gets the current values -- this can be expanded from the
above sample, of course.
locale {all|collate|messages|monetary|numeric|time} {{}|<locale>|-get}

Now obviously there are dozens of ways this could be done. What would
you like to see?

Could have:
locale values
decimal_point , thousands_sep . grouping 33 currency_symbol €
locale get {all|collate|messages|monetary|numeric|time}
locale set {all|collate|messages|monetary|numeric|time} {{}|<locale>}

Or
locale values
locale {all|collate|messages|monetary|numeric|time} get
locale {all|collate|messages|monetary|numeric|time} set {{}|<locale>}

Other ideas?
Should the empty string be changed to an actual command
(e.g. -from-environment)?

I don't understand the 'localeconv()->grouping' return. Some languages have
'33', some have '3', ja_JP should have '4', but has '3'. It seems bogus.
I don't have an Indian locale installed, so can't check that right now.
The zh_CN and zh_TW return a grouping of '3' also, should be '4', I think.

What values would you like to see from localeconv()?

My program only really requires collate/messages/and the decimal_point,
and I realized I was not processing decimal points, so I need an upgrade.

So I thought I might as well get most of the useful stuff in there.

References:
man 7 locale
man 3 localeconv
man 3 setlocale

Brad Lanam

unread,
Aug 2, 2018, 6:56:46 PM8/2/18
to
% load [pwd]/../src/locale.so
% locale all {}
% load [pwd]/../src/locale.so
% locale all {}
de_DE.UTF-8
% ttk::frame -height 1.5p
invalid command name "ttk::frame"
% package require Tk
8.6.8
% ttk::frame -height 1.5p
wrong # args: should be "ttk::frame pathName ?-option value ...?"
% ttk::frame .f -height 1.5p
bad screen distance "1.5p"
% ttk::frame .f -height 1,5p
.f

Ouch. This is going to be tricky.
Makes it a lot harder to use locales.

Brad Lanam

unread,
Aug 2, 2018, 7:23:58 PM8/2/18
to
On Thursday, August 2, 2018 at 3:56:46 PM UTC-7, Brad Lanam wrote:
> Ouch. This is going to be tricky.
> Makes it a lot harder to use locales.

And spinboxes are a pain. I'll probably have to write my own.

Ralf Fassel

unread,
Aug 3, 2018, 4:57:09 AM8/3/18
to
* Brad Lanam <brad....@gmail.com>
| % ttk::frame .f -height 1.5p
| bad screen distance "1.5p"
| % ttk::frame .f -height 1,5p
| .f
>
| Ouch. This is going to be tricky.
| Makes it a lot harder to use locales.

Yes, this is why we tried to avoid them as best as we could.

Plus, what about Windows? I would rather not have
if-not-windows-use-locale-else
in my programs... (As an aside, we once got bitten by a printer driver
which changed the number formatting scheme, so that 1.5 was no longer
accepted as float after the printer was used the first time from TCL.
Took some time to debug this one :-)...

R'

Brad Lanam

unread,
Aug 3, 2018, 9:11:59 AM8/3/18
to
On Friday, August 3, 2018 at 1:57:09 AM UTC-7, Ralf Fassel wrote:
> * Brad Lanam <brad>
> | % ttk::frame .f -height 1.5p
> | bad screen distance "1.5p"
> | % ttk::frame .f -height 1,5p
> | .f
> >
> | Ouch. This is going to be tricky.
> | Makes it a lot harder to use locales.
>
> Yes, this is why we tried to avoid them as best as we could.

That should get fixed, IMHO.
Unfortunately, it's a bit harder to fix than it first looks.
I'd like to know how other dynamic scripting languages solved it.

Anyways, I set LC_NUMERIC to C in my application after fetching the
numeric locale. I expect this will need to be moved into the locale
module.

> Plus, what about Windows? I would rather not have
> if-not-windows-use-locale-else
> in my programs... (As an aside, we once got bitten by a printer driver
> which changed the number formatting scheme, so that 1.5 was no longer
> accepted as float after the printer was used the first time from TCL.
> Took some time to debug this one :-)...

Windows is not an issue.
Except for LC_MESSAGES.
Windows doesn't have that.

I'm inclined that for a 'get' of LC_MESSAGES, LC_ALL should be returned.
But for a 'set', I think setting LC_ALL is a bit dangerous.
Maybe just ignore the set of LC_MESSAGES on windows?
Or keep it as an internal variable?

And I ran into another bug in Tcl, the 'scan' command is not locale
friendly. ('format' is).

I have a localized spinbox mostly written. Couple more things to do
with it.

Brad Lanam

unread,
Aug 3, 2018, 11:49:39 AM8/3/18
to
Usage will be:

load locale.so

# Initialize all LC_* settings from the environment.
# Note that the LC_NUMERIC locale is saved internally, and reset to 'C'.
locale all set {}

# [locale values] returns some information if you want to use
# it directly in your program.
# Note that either: locale all set {} must be called,
# or 'numeric' and 'monetary' locale settings must be set.
# and as outlined below, 'numeric' must be reverted back to 'C'.
# This can be expanded to return more information if wanted.
locale values
-> decimal_point , thousands_sep . grouping 33 currency_symbol €

# Getting LC_NUMERIC will return the correct value, though
# in reality, it is still set to 'C'.
locale numeric get
-> de_DE.UTF-8

# the format statement is locale aware
# setting LC_NUMERIC explicitly works, but you have to remember to
# change it back
locale numeric set de_DE.UTF-8
set x [format %.1f 1.5]
-> 1,5
locale numeric set C

# scan is not locale aware (<unhappy>)
# this regsub handles 90+% of the different locales, I expect
regsub , $x . x
scan $x %f myvalue

# On windows LC_MESSAGES returns the LC_ALL setting
locale messages get
-> de_DE.UTF-8

# Windows: setting LC_MESSAGES saves the value, but doesn't change any
# locale settings.
locale messages set en_US.UTF-8
locale messages get
-> en_US.UTF-8

I already have a collate function written for use with lsort.
https://sourceforge.net/p/tcl-collate/code/ci/default/tree/
(The setlocale.c code there *only* sets LC_COLLATE).

I also have a localized, (and should be scalable) spinbox written.
The localized spinbox needs more testing, but everything seems to be ok.

The new locale.c needs testing on windows.

Brad Lanam

unread,
Aug 5, 2018, 11:49:29 AM8/5/18
to
I have added the new 'locale' command to the tcl-collate project
on sourceforge:
https://sourceforge.net/p/tcl-collate/code/ci/default/tree/

Brad Lanam

unread,
Aug 5, 2018, 12:08:17 PM8/5/18
to
And the pre-compiled libraries are available:
https://sourceforge.net/projects/tcl-collate/files/
0 new messages