commit:     8065bb9fedfe32df1762fe9ba190cf58cf6285d1
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jan  4 22:13:20 2026 +0000
Commit:     Kerin Millar <kfm <AT> plushkava <DOT> net>
CommitDate: Sun Jan  4 22:13:20 2026 +0000
URL:        https://gitweb.gentoo.org/proj/locale-gen.git/commit/?id=8065bb9f

Introduce the LOCALEGEN_ALLOW_UNSUPPORTED environment variable

Support a new environment variable, named LOCALEGEN_ALLOW_UNSUPPORTED.
If set as a non-empty string, errors caused by locale-gen(8) being
unable to validate its configuration file shall be conveyed as mere
warnings, with the exception of any that concern malformed entries.
However, errors caused by localedef(1) being unable to compile a given
locale shall still be considered as fatal.

This feature makes it possible for those experimenting with custom
locale templates to actually use locale-gen(8), rather than have to
independently execute localedef(1). Naturally, anyone that makes use of
this feature should do so under the understanding that it is at their
own risk.

Requested-by: Mazunki Hoksaas <rolferen <AT> gmail.com>
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 locale-gen   | 25 +++++++++++++++++--------
 locale-gen.8 |  3 +++
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/locale-gen b/locale-gen
index f373d8f..cee7ec3 100644
--- a/locale-gen
+++ b/locale-gen
@@ -72,8 +72,12 @@ umask 0022;
        # Compose a dictionary of supported locale/charmap combinations.
        my $supported_by = map_supported_combinations($prefix);
 
+       # Allow for the user to demote locale.gen(5) validation errors to mere
+       # warnings, while still treating localedef(1) errors as being critical.
+       my $be_strict = ! length $ENV{'LOCALEGEN_ALLOW_UNSUPPORTED'};
+
        # Collect the locales that are being requested for installation.
-       push @locales, read_config($prefix, $supported_by, @config_files);
+       push @locales, read_config($prefix, $supported_by, $be_strict, 
@config_files);
 
        # Compose a dictionary of installed locales for the --update option.
        my %installed_by;
@@ -279,7 +283,7 @@ sub normalize ($canonical) {
        }
 }
 
-sub read_config ($prefix, $supported_by, @paths) {
+sub read_config ($prefix, $supported_by, $be_strict, @paths) {
        # Iterate over the given paths and return the first non-empty list of
        # valid locale declarations that can be found among them, if any.
        for my $i (keys @paths) {
@@ -296,7 +300,7 @@ sub read_config ($prefix, $supported_by, @paths) {
                                die $e;
                        }
                }
-               my @locales = parse_config($fh, $path, $supported_by);
+               my @locales = parse_config($fh, $path, $supported_by, 
$be_strict);
                if (my $count = scalar @locales) {
                        printf "Found %d locale declaration%s in '%s'.\n",
                                $count, plural($count), $path;
@@ -339,11 +343,16 @@ sub map_supported_combinations ($prefix) {
        return \%supported_by;
 }
 
-sub parse_config ($fh, $path, $supported_by) {
+sub parse_config ($fh, $path, $supported_by, $be_strict) {
        # Set up a helper routine to throw for validation errors.
-       my $thrower = sub ($error, $line) {
-               die sprintf "%s: %s at %s[%d]: %s\n",
-                       $PROGRAM, $error, $path, $., render_printable($line);
+       my $thrower = sub ($error, $line, $is_fatal = 0) {
+               if ($be_strict || $is_fatal) {
+                       die sprintf "%s: %s at %s[%d]: %s\n",
+                               $PROGRAM, $error, $path, $., 
render_printable($line);
+               } else {
+                       print_warning(sprintf "WARNING! %s at %s[%d]: %s\n",
+                               $error, $path, $., render_printable($line));
+               }
        };
 
        my @locales;
@@ -359,7 +368,7 @@ sub parse_config ($fh, $path, $supported_by) {
                my ($locale, $charmap);
                chomp $line;
                if (2 != (($locale, $charmap) = split /\h+/, trim_line($line))) 
{
-                       $thrower->('Malformed locale declaration', $line);
+                       $thrower->('Malformed locale declaration', $line, 1);
                }
 
                # Handle "UTF8" as a special case. Though glibc tolerates it,

diff --git a/locale-gen.8 b/locale-gen.8
index fc208ad..d423cb8 100644
--- a/locale-gen.8
+++ b/locale-gen.8
@@ -70,6 +70,9 @@ Contains character map files that serve as inputs to 
\fBlocaledef\fR(1).
 .TP
 LOCALEGEN\_CONFIG
 Defines the path of the \fIconfig\fR file in the absence of the \fB-A\fR and 
\fB-c\fR options.
+.TP
+LOCALEGEN\_ALLOW\_UNSUPPORTED
+If set as a non-empty string, errors caused by locale\-gen being unable to 
validate the \fIconfig\fR file shall be conveyed as mere warnings, with the 
exception of any that concern malformed entries. However, errors caused by 
\fBlocaledef\fR(1) being unable to compile a given locale shall still be 
considered as fatal.
 .SH "EXIT STATUS"
 The exit status shall be 0 under any of these conditions:
 .IP \[bu] 2

Reply via email to