The time now is Thu 20 Jun 2013, 05:34
All times are UTC - 4 |
| Author |
Message |
Argolance

Joined: 06 Jan 2008 Posts: 1407 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Wed 07 Dec 2011, 07:07 Post subject:
How to get the right current locale decimal mark? Subject description: (Running Wary 5.2.2) |
|
Hello,
I need to get the decimal mark currently used by the system for a script to run properly according to the locale settings. French, German, Spanish... are using comma, English, Japan... point. The problem is that, while setting my locale as French for instance, I get the wrong mark using these simple code lines to get it: | Quote: | # a=$(echo "scale=2;100/3"|bc)
# echo $a
33.33
# |
I already tried others ways to solve the problem like getting the current locale and, while listing all locales supposed to use point, conditionally run the script with, and with comma if not listed... Of course, this doesn't match every time and I thought it should be easier to get the current mark directly.
How could I solve this? As far as I know, this problem has, at least, to be solved for all scripts using gtk hscale or vscale!
Best regards.
_________________

|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1804 Location: Burghaslach, Germany
|
Posted: Wed 07 Dec 2011, 09:06 Post subject:
Re: How to get the right current decimal mark? Subject description: decimal_point |
|
# grep -A4 ^LC_NUMERIC /usr/share/i18n/locales/${LANG%.*}
LC_NUMERIC
decimal_point "<U002C>"
thousands_sep "<U002E>"
grouping 3;3
END LC_NUMERIC
#
2C is ,
2E is .
Or just:
grep ^decimal_point /usr/share/i18n/locales/${LANG%.*}
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2737 Location: Kiel,Germany
|
Posted: Thu 08 Dec 2011, 00:08 Post subject:
|
|
I would probably simply use
| Code: | echo $LANG
LANG=C dc 1000 3 \/ p
echo $LANG |
This should set the locale just for the line/command , not for the whole script .
|
|
Back to top
|
|
 |
Argolance

Joined: 06 Jan 2008 Posts: 1407 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Thu 08 Dec 2011, 06:22 Post subject:
Subject description: GTK+ >= 2.16.0. |
|
Hello,
Thank you Karl Godt and L18L for replying.
@L18L
I think what you suggested is a good way to get the decimal mark and contribute to find a solution to a problem that concerns all scripts using non monetary decimal values (Please see => JMW theme configuration)
A bit more complicated though, because all locales files don't give the decimal_point value directly but through another locale config file that is "copied" instead:
| Quote: | LC_NUMERIC
copy "de_BE"
[...] | ... for instance.
I add code lines to this hscale script based on the original (from gtkdialog(4) svn repository by thunor):
| Quote: | #!/bin/sh
GTKDIALOG=gtkdialog
#get current Decimal Mark
DM_tmp=$(grep ^decimal_point /usr/share/i18n/locales/${LANG%.*} | cut -d'<' -f2 | sed 's/>"//')
if [[ -z $DM_tmp ]]; then
echo $(grep -A4 ^LC_NUMERIC /usr/share/i18n/locales/${LANG%.*}) > /tmp/LC_N_temp
locale=$(cat /tmp/LC_N_temp | cut -d '"' -f2)
DM_tmp=$(grep ^decimal_point /usr/share/i18n/locales/$locale | cut -d'<' -f2 | sed 's/>"//')
fi
if [[ $DM_tmp = "U002C" ]]; then
DM=","
else
DM="."
fi
export MAIN_DIALOG='
<window title="Decimal Mark Test" resizable="true">
<vbox>
<frame hscale widget>
<hscale space-expand="true" space-fill="true"
width-request="200" height-request="20"
value-pos="0"
range-min="0'$DM'3" range-max="30'$DM'7"
range-step="0'$DM'1" range-value="15'$DM'5">
<variable>HSCALE</variable>
</hscale>
</frame>
<hbox homogeneous="true">
<button ok></button>
</hbox>
</vbox>
<action signal="hide">exit:Exit</action>
</window>
'
$GTKDIALOG --program=MAIN_DIALOG
|
This should probably be polished up because (no use to say!) I am not an expert in code lines but it works fine (seems to work?) with any locale and this was the purpose!
Best regards.
_________________

|
|
Back to top
|
|
 |
Argolance

Joined: 06 Jan 2008 Posts: 1407 Location: PORT-BRILLET (Mayenne - France)
|
Posted: Thu 08 Dec 2011, 11:20 Post subject:
|
|
Hello Karl Godt, | Karl Godt wrote: | I would probably simply use
| Code: | echo $LANG
LANG=C dc 1000 3 \/ p
echo $LANG |
This should set the locale just for the line/command , not for the whole script . |
I was wondering how could this be done taking the script above as example?
Thank you a lot.
Regards
_________________

|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1804 Location: Burghaslach, Germany
|
Posted: Tue 13 Dec 2011, 15:16 Post subject:
|
|
Maybe this is faster without copy, I don´t know
# pwd
/usr/lib/locale/de_DE
# cat LC_NUMERIC
"$(,0,.,.ISO-8859-1#
# pwd
/usr/lib/locale/en_US
# cat LC_NUMERIC
"$(,0.,.,ISO-8859-1#
|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|