Browse Source

* Evaluates all 3 i18n environment variables: LC_ALL, LC_MESSAGES, LANG
* Now takes sublanguage specifiers into account: When the language is set
to xx_YY, then the catalogue for xx will be loaded first, and then the
catalogue for sublanguage xx_YY will be loaded and applied as well.

sg 24 years ago
parent
commit
d038536ca8
1 changed files with 34 additions and 4 deletions
  1. 34 4
      fcl/inc/gettext.pp

+ 34 - 4
fcl/inc/gettext.pp

@@ -1,7 +1,7 @@
 {
 {
     $Id$
     $Id$
     This file is part of the Free Pascal run time library.
     This file is part of the Free Pascal run time library.
-    Copyright (c) 1999-2000 by the Free Pascal development team
+    Copyright (c) 1999-2001 by the Free Pascal development team
 
 
     Gettext interface to resourcestrings.
     Gettext interface to resourcestrings.
 
 
@@ -263,9 +263,33 @@ end;
 procedure TranslateResourceStrings(const AFilename: String);
 procedure TranslateResourceStrings(const AFilename: String);
 var
 var
   mo: TMOFile;
   mo: TMOFile;
-  lang: String;
+  lang, FallbackLanguage: String;
 begin
 begin
-  lang := Copy(GetEnv('LANG'), 1, 2);
+  lang := GetEnv('LC_ALL');
+  if Length(lang) = 0 then
+  begin
+    lang := GetEnv('LC_MESSAGES');
+    if Length(lang) = 0 then
+    begin
+      lang := GetEnv('LANG');
+      if Length(lang) = 0 then
+        exit;	// no language defined via environment variables
+    end;
+  end;
+
+  FallbackLanguage := Copy(lang, 1, 2);
+  try
+    mo := TMOFile.Create(Format(AFilename, [FallbackLanguage]));
+    try
+      TranslateResourceStrings(mo);
+    finally
+      mo.Free;
+    end;
+  except
+    on e: Exception do;
+  end;
+
+  lang := Copy(lang, 1, 5);
   try
   try
     mo := TMOFile.Create(Format(AFilename, [lang]));
     mo := TMOFile.Create(Format(AFilename, [lang]));
     try
     try
@@ -286,7 +310,13 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2000-11-23 10:19:31  sg
+  Revision 1.4  2001-09-21 12:52:54  sg
+  * Evaluates all 3 i18n environment variables: LC_ALL, LC_MESSAGES, LANG
+  * Now takes sublanguage specifiers into account: When the language is set
+    to xx_YY, then the catalogue for xx will be loaded first, and then the
+    catalogue for sublanguage xx_YY will be loaded and applied as well.
+
+  Revision 1.3  2000/11/23 10:19:31  sg
   * optimized the string translation process a little bit
   * optimized the string translation process a little bit
 
 
   Revision 1.2  2000/07/13 11:32:59  michael
   Revision 1.2  2000/07/13 11:32:59  michael