30

I need to find a list of locale installed/supported in my linux machine. is there a way to find a list of valid locales in my linux using perl ?

thanks

Nelson
  • 49,283
  • 8
  • 68
  • 81
user1318538
  • 321
  • 1
  • 5
  • 6

5 Answers5

48

This command will give you a list of locales:

locale -a

From a Perl script you can execute the same using

system("locale -a");
Jean
  • 21,665
  • 24
  • 69
  • 119
9

If you want the list of all supported locales, in my Debian distro they are in /usr/share/i18n/SUPPORTED , so you could do:

system("cat /usr/share/i18n/SUPPORTED");
Nelson
  • 49,283
  • 8
  • 68
  • 81
  • This one actually works :) +1 An alternative is : `less /usr/share/i18n/SUPPORTED` which of course provides you with the option to search for a "locales of interest". –  Mar 31 '22 at 17:42
2
my @locale_list = `locale -a`;
chomp(@locale_list);
Galimov Albert
  • 7,269
  • 1
  • 24
  • 50
2

http://perldoc.perl.org/perllocale.html#Finding-locales:

For locales available in your system, consult also setlocale(3) to see whether it leads to the list of available locales (search for the SEE ALSO section). If that fails, try the following command lines:

locale -a
nlsinfo
ls /usr/lib/nls/loc
ls /usr/lib/locale
ls /usr/lib/nls
ls /usr/share/locale
ysth
  • 96,171
  • 6
  • 121
  • 214
0

if by saying "valid locales" you wanted to check which locales are supported

then you need to go to the file (you can open it with 'nano' to check if it is still there)

nano /usr/share/i18n/SUPPORTED

tested on Ubuntu 18

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191