[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: es_419 language code



On Wed, 13 Apr 2022 11:34:55 +0200
Eberhard Beilharz <eb1@sil.org> wrote:

> Hi,
> 
> The automatic checks complain about a few of the language codes we use 
> [1]. Most are errors in our naming, except one:
> 
> gettext: linux/keyman-config/locale/es_419.po: can't guess language
> 
> To my knowledge *es_419* is a valid language code for Spanish spoken in 
> Latin America (419 is the region code for Latin America). Would it be 
> possible to enhance the checks so that it recognizes and accepts that code?
> 
> Thanks,
>      Eberhard
> 
> [1] https://i18n.debian.org/l10n-pkg-status/k/keyman.html

The following should fix it (dl10n project [1]).

add_country() is used, because Locale::Codes lacks region code 419.

Probably, similar changes should be done in webwml in english/international/l10n/scripts/transmonitor-check.

[1] https://salsa.debian.org/l10n-team/dl10n

--- orig/dl10n-check
+++ new/dl10n-check
@@ -21,6 +21,7 @@
 
 use Locale::Language;
 use Locale::Country;
+Locale::Country::add_country(419, "Latin America and the Caribbean", LOCALE_CODE_NUMERIC);
 
 use Debian::L10n::Db;
 use Debian::L10n::Debconf;
@@ -662,7 +663,7 @@
         my $bad_lang=""; #this could be a language, but this is not a valid language
         my $this_stat = ""; #stats for this file
         my $err_msg =""; # err msg of the statistic external command (ie, msgfmt or debconf-stats)
-        my $regexp_for_lang_code = '(([a-zA-Z]{2,3})([-_][a-zA-Z]{2})?(@[^./]*)?)(\.[^./]+)?';
+        my $regexp_for_lang_code = '(([a-zA-Z]{2,3})([-_]([a-zA-Z]{2}|\d{3}))?(@[^./]*)?)(\.[^./]+)?';
 
         $filename = store_temp($pkg, $file);
 
@@ -955,7 +956,7 @@
 sub normalize_lang {
         my $lang = shift;
         $lang =~ s/\..*$//;
-        if ($lang =~ m,^(...?)[-_](..)$,) {
+        if ($lang =~ m,^(...?)[-_](...?)$,) {
                 return lc($1).'_'.uc($2);
         } elsif ($lang =~ m,^(...?)$,) {
                 return lc($1);
@@ -1016,7 +1017,7 @@
         close (DATA);
 }
 
-# sub is_lang(code) : returns true iff code is a valide code of language
+# sub is_lang(code) returns true if code is a valid language code
 sub is_lang {
         my $code = shift;
         $code =~ s/\@.*$//;
@@ -1024,19 +1025,22 @@
         my $checklanguage = sub {
                 my $lang = shift;
                 my $len = length $lang;
-                if ($len eq 2) {
+                if ($len == 2) {
                         return defined code2language($lang, LOCALE_LANG_ALPHA_2);
-                } elsif ($len eq 3) {
+                } elsif ($len == 3) {
                         return defined code2language($lang, LOCALE_LANG_ALPHA_3);
                 }
                 return 0;
         };
 
-        #   Accept these codes
+        # Accept these codes
         return 1 if $code eq 'cz' || $code eq 'dk' || $code eq 'sp';
         if ($code =~ /^(...?)[-_](..)$/) {
                 return (&$checklanguage($1) && defined(code2country($2)));
         }
+        elsif ($code =~ /^(...?)[-_](...)$/) {
+                return (&$checklanguage($1) && defined(code2country($2, LOCALE_CODE_NUMERIC)));
+        }
         return &$checklanguage($code);
 }


Reply to: