2
0

langid.ph 306 B

1234567891011121314151617181920212223
  1. #!/usr/bin/perl
  2. use strict;
  3. use integer;
  4. our %langid;
  5. require 'lcid.ph';
  6. sub langid($) {
  7. my($s) = @_;
  8. $s = lc($s);
  9. $s =~ s/\P{Alnum}+/-/g;
  10. while (1) {
  11. my $lcid = $langid{$s};
  12. return $lcid if (defined($lcid));
  13. last unless ($s =~ /(.*)\-[^-]+$/);
  14. $s = $1;
  15. }
  16. return undef;
  17. }