Author Topic: Query on the Linux command  (Read 4897 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Query on the Linux command
« on: October 01, 2018, 02:12:28 pm »
Does anyone know of how to get a LCID from a Linux command line? (the identity of the national environment). I need it in one program in QB64. Thanks for reply.

Marked as best answer by Petr on October 02, 2018, 08:21:49 am

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Query on the Linux command
« Reply #1 on: October 01, 2018, 03:00:45 pm »
Hi Petr

Does anyone know of how to get a LCID from a Linux command line? (the identity of the national environment). I need it in one program in QB64. Thanks for reply.

On Linux, in order to display the messages with the appropriate desktop language in my different bash scripts, I use the command "echo $LANG ⎥cut -c1,2" that provides the two first letters of the language in use.

e.g. On an US Linux system, the command "echo $LANG" will respond: "en_US.UTF-8" when the command "echo $LANG ⎥cut -c1,2" will show only: "en"

Few samples  below:

- en for english
- de for deuch
- es for spanish
- fr for french
- be for russian
- it for italian
- pt for portugese
etc.

Hope this helps.

Cheers.
Fifi

Note: I just also ran that command on my Imac27 with OS/X and it's the same result. Don't know about Windows 10 since I did not install the bash support yet but that should be the same (thanx to Lord MSFT). LoL.
« Last Edit: October 01, 2018, 04:16:51 pm by Fifi »
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Query on the Linux command
« Reply #2 on: October 01, 2018, 03:15:34 pm »
Thank you fifi, I can try it this way. But is here way to list the identification number of the language directly? As is 4105 for english in Canada  or  2057 is for english in great britain...

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Query on the Linux command
« Reply #3 on: October 01, 2018, 03:19:48 pm »
Thank you fifi, I can try it this way. But is here way to list the identification number of the language directly? As is 4105 for english in Canada  or  2057 is for english in great britain...

I've no clue since my method was enough for my needs but I can ask arround on different forum I'm familliar with. I'll let you know as soon as I'll get any answer.
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Query on the Linux command
« Reply #4 on: October 01, 2018, 03:27:37 pm »
It will actually be enough if Linux lists me for my speech either 1250 or 405, I will try it in my system. I will know the result tomorrow. I assume that the LCID will be the same in both Windows and Linux. If you find it out, it would help me.
Thank you.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Query on the Linux command
« Reply #5 on: October 01, 2018, 03:31:02 pm »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Query on the Linux command
« Reply #6 on: October 01, 2018, 03:42:46 pm »
getenv "LANG" should work for you, I'd think.

https://www.tutorialspoint.com/c_standard_library/c_function_getenv.htm

And ENVIRON$ may be able to give you that information natively.  See if this gives any language info for you:
 
DO
  i = i + 1
  setting$ = ENVIRON$(i) ' get a setting from the list
  PRINT setting$
  IF i MOD 20 = 0 THEN PRINT "Press a key": SLEEP: CLS
LOOP UNTIL setting$ = ""
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Query on the Linux command
« Reply #7 on: October 01, 2018, 04:26:36 pm »
BTW, I forgot to say that the command "echo $LANG ⎥cut -c1,2,4,5" will display "enUS" on an American-English system with the "cut arguments "-c1,2,4,5" displaying only the caharcters 1,2 then 4 and 5 and not the 3 (i.e. the "_") nor the end of the command.

I'll try later with VMs using different language settings just to know and I'll return ASAP.

Cheers.
fifi
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Query on the Linux command
« Reply #8 on: October 01, 2018, 04:48:56 pm »
Another thing,

On Ubuntu 18.04.1 (Bionic) that I run, I just made 2 changes in the Settings, option Region & Language, from English(United States) to English(Canada) in the Language entry field as well as in the Formats entry field and the command "echo $LANG ⎥cut -c1,2,4,5" displays "enCA".

When I changed the both these settings to English (United Kingdom), the command "echo $LANG ⎥cut -c1,2,4,5" displays "enGB".

While I don't respond exactly to your request for the number value of the language used yet, this way should solve your problem, willn't it?

Cheers.
Fifi
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Query on the Linux command
« Reply #9 on: October 01, 2018, 05:08:24 pm »
Thank you Fifi and Steve for the answers, I will try it out in Linux tomorrow and I will let you know. I have to go to sleep.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Query on the Linux command
« Reply #10 on: October 02, 2018, 10:39:38 am »
Thank you again for your answers. I'll add strings to the LCID program because the numeric designation, as I found , is for Windows only. To do this, I use the Israeli convert table here: https://www.science.co.il/language/Locale-codes.php


For Steve: Environ$ contains not this information.

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: Query on the Linux command
« Reply #11 on: October 02, 2018, 03:44:46 pm »
Hi Petr

Thank you again for your answers. I'll add strings to the LCID program because the numeric designation, as I found , is for Windows only. To do this, I use the Israeli convert table here: https://www.science.co.il/language/Locale-codes.php

For Steve: Environ$ contains not this information.

When reading the Israeli table, it seams better to use (what ever the OS is Linux or OS/X) the LCID string that displays both the language and the keyboard layout used on the machine.

So, with Linux and OS/X, the command I would use is: "echo $LANG ⎥cut -c1,2,3,4,5" that displays "en-GB " on an English OS with an Great Britain keyboard.

However, I don't know how this works with Windows.

Could you provide a command sample for the Windows OS?

King regards.
Fifi
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Query on the Linux command
« Reply #12 on: October 02, 2018, 04:09:35 pm »
Hi Fifi,

I use PowerShell for this purpose and his get-culture command. However, the output file is formatted so I read it binary and write only numeric values.
I found, that some countries contains none LCID string, so this are not supported in my program. It is just small portion of one much bigger program.