Onscreen format

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Onscreen format

Post by AndyGable »

Hi everyone

I've been working on a small update to my software and I need some advice

I have the following format working "£0.00" but when I try to change the app to US mode the system displays "0.00" even though I am formatting the data with "$0.00" (format(totaldue, "$0.00")

Also when I try EU mode the system shows me 001 for a price of 65

The format is "0,00 €" so I would be using format(totaldue, "0,00 €")


Could someone guide me on how I can get the other 2 options to work?


Most kind

Andy
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Onscreen format

Post by cogier »

That was an interesting little problem.

The first point to make is that if your computer's language does not support the currency you want, i.e. English does support the Dollar and the GB Pound but not the Euro for example, you will need to install the relevant language pack. See in the code below.

Public Sub Form_Open()

  Dim fValue As Float = 2.56

  System.Language = "de_DE.UTF-8" ''Needed to install language pack (sudo apt-get install language-pack-de)
  Print Format(fValue, gb.Currency)

  System.Language = "en_GB.UTF-8"
  Print Format(fValue, gb.Currency)

  System.Language = "en_US.UTF-8"
  Print Format(fValue, gb.Currency)

End


The output is: -
2,56 €
£2.56
$2.56
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: Onscreen format

Post by thatbruce »

Well said Cogier!
This is such a common problem for everybody. When one "expects" that a format or a translation or whatever, one has to ask "Is the relevant language installed?"
To ask for a possible improvement though, if the said language (say "sp.ca" for instance) is not installed then how in a general way can it be tested for?
To expand, lets say the user has a natural language of "South Australian Indigenous" which of course does not exist as far as the internet is concerned. Let's try to test for the supposed language "en.au.ng". That may sound a little bit parochial but but how to handle en.us.mohawk or en.uk.scouse etc.
Joking aside, how would you describe a way we can avoid the impossible, because the "language" is not installed?
b
(I have not ever found a solution :( )
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Onscreen format

Post by cogier »

To ask for a possible improvement though, if the said language (say "sp.ca" for instance) is not installed then how in a general way can it be tested for?
The Linux CLI command to show all the installed languages is locale -a

I have altered the above code to show the list: -

Public Sub Form_Open()
  
  Dim fValue As Float = 2.56
  Dim sLocale As String
  
  Shell "locale -a" To sLocale
  Print sLocale 
  
  System.Language = "de_DE.UTF-8" ''Needed to install language pack (sudo apt-get install language-pack-de)
  Print Format(fValue, gb.Currency)
  
  System.Language = "en_GB.UTF-8"
  Print Format(fValue, gb.Currency)
  
  System.Language = "en_US.UTF-8"
  Print Format(fValue, gb.Currency)
  
End


The output on my computer is:-
C
C.utf8
de_AT.utf8
de_BE.utf8
de_CH.utf8
de_DE.utf8
de_IT.utf8
de_LI.utf8
de_LU.utf8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IL
en_IL.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

2,56 €
£2.56
$2.56
Post Reply