Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 25 Oct 2014, 02:44
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to get the right current locale decimal mark?
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Wed 07 Dec 2011, 07:07    Post_subject:  How to get the right current locale decimal mark?
Sub_title: (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
#

Shocked

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
View user's profile Send_private_message Visit_website 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Wed 07 Dec 2011, 09:06    Post_subject: Re: How to get the right current decimal mark?
Sub_title: 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 .
Smile

Or just:
grep ^decimal_point /usr/share/i18n/locales/${LANG%.*}
Back to top
View user's profile Send_private_message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: 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
View user's profile Send_private_message Visit_website 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 08 Dec 2011, 06:22    Post_subject:
Sub_title: 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 Embarassed but it works fine (seems to work?) with any locale and this was the purpose! Very Happy

Best regards.

_________________

Back to top
View user's profile Send_private_message Visit_website 
Argolance


Joined: 06 Jan 2008
Posts: 1839
Location: PORT-BRILLET (Mayenne - France)

PostPosted: 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
View user's profile Send_private_message Visit_website 
L18L

Joined: 19 Jun 2010
Posts: 2530
Location: Moved from Hosla to www.eussenheim.de

PostPosted: 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
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0564s ][ Queries: 11 (0.0039s) ][ GZIP on ]