#!/usr/bin/perl use strict; use warnings; use 5.01; # get the locales available on the system my @avail_locales = map { chomp; s/\.utf8//; $_ } qx( locale -a | grep \.utf8 ); # add items without country code to facilitate lookups my %extended_localelist; for my $loc (@avail_locales) { ( my $lang = $loc ) =~ s/_[A-Z]+//; @extended_localelist{$loc, $lang} = (1, 1); } # get the union of /usr/share/locale-langpack and /usr/share/locale my %translation_dirs; opendir my $dh, '/usr/share/locale-langpack' or die $!; $translation_dirs{$_} = 1 for readdir $dh; opendir $dh, '/usr/share/locale' or die $!; $translation_dirs{$_} = 1 for readdir $dh; # get the intersection of available translation_dirs and the extended locale list my %intersection; for ( keys %extended_localelist ) { $intersection{$_} = 1 if $translation_dirs{$_}; } # Remove items without country code if country code items in the same language # exist, since gettext won't find a translation under e.g. 'de_DE' if the # first item in LANGUAGE is 'de' (see https://launchpad.net/bugs/700213). # 'en' is kept, though, since it's always the last item in LANGUAGE per design. my %count; for ( keys %intersection ) { next if /^en[^a-z]/; ( my $not_country = $_ ) =~ s/_[A-Z]+//; $count{$not_country} ++; } for ( keys %count ) { if ( $count{$_} > 1 and $intersection{$_} ) { delete $intersection{$_}; } } # print the resulting list of language options say for sort keys %intersection;