changeset 349:a0711c57c1db

- Added variable 'lang_code' to language files. - Changed the variable 'language' in config.d to 'langfile'. It must contain the path to the language file.
author aziz
date Sat, 25 Aug 2007 11:13:01 +0000
parents 206d305b2706
children 4ea6759300cf
files trunk/src/config.d trunk/src/dil/Settings.d trunk/src/lang_de.d trunk/src/lang_en.d trunk/src/lang_tr.d
diffstat 5 files changed, 46 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/config.d	Fri Aug 24 22:55:02 2007 +0000
+++ b/trunk/src/config.d	Sat Aug 25 11:13:01 2007 +0000
@@ -1,1 +1,1 @@
-option language = "en";
+option langfile = "lang_en.d";
--- a/trunk/src/dil/Settings.d	Fri Aug 24 22:55:02 2007 +0000
+++ b/trunk/src/dil/Settings.d	Sat Aug 25 11:13:01 2007 +0000
@@ -62,59 +62,65 @@
     foreach (decl; root.children)
     {
       auto v = Cast!(VariableDeclaration)(decl);
-      if (v && v.idents[0].srcText == "language")
+      if (v && v.idents[0].srcText == "langfile")
       {
         auto e = v.values[0];
         if (!e)
-          throw new Exception("language variable has no value set.");
+          throw new Exception("langfile variable has no value set.");
         auto val = Cast!(StringLiteralsExpression)(e);
         if (val)
         {
-          GlobalSettings.language = val.getString();
+          // Set fileName to d-file with messages table.
+          fileName = val.getString();
           break;
         }
       }
     }
 
     // Load messages
-    if (GlobalSettings.language.length)
+    sourceText = cast(char[]) std.file.read(fileName);
+    parser = new Parser(sourceText, fileName);
+    parser.start();
+    root = parser.parseModule();
+
+    if (parser.errors.length || parser.lx.errors.length)
     {
-      fileName = "lang_" ~ GlobalSettings.language ~ ".d";
-      sourceText = cast(char[]) std.file.read(fileName);
-      parser = new Parser(sourceText, fileName);
-      parser.start();
-      root = parser.parseModule();
+      throw new Exception("There are errors in "~fileName~".");
+    }
 
-      if (parser.errors.length || parser.lx.errors.length)
+    char[][] messages;
+    foreach (decl; root.children)
+    {
+      auto v = Cast!(VariableDeclaration)(decl);
+      if (v is null)
+        continue;
+      if (v.idents[0].srcText == "messages")
       {
-        throw new Exception("There are errors in "~fileName~".");
-      }
-
-      char[][] messages;
-      foreach (decl; root.children)
-      {
-        auto v = Cast!(VariableDeclaration)(decl);
-        if (v && v.idents[0].srcText == "messages")
+        auto e = v.values[0];
+        if (!e)
+          throw new Exception("messages variable in "~fileName~" has no value set.");
+        if (auto array = Cast!(ArrayInitializer)(e))
         {
-          auto e = v.values[0];
-          if (!e)
-            throw new Exception("messages variable in "~fileName~" has no value set.");
-          if (auto array = Cast!(ArrayInitializer)(e))
+          foreach (value; array.values)
           {
-            foreach (value; array.values)
-            {
-              if (auto str = Cast!(StringLiteralsExpression)(value))
-                messages ~= str.getString();
-            }
+            if (auto str = Cast!(StringLiteralsExpression)(value))
+              messages ~= str.getString();
           }
-          else
-            throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer.");
         }
+        else
+          throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer.");
       }
-      if (messages.length != MID.max+1)
-        throw new Exception(std.string.format("messages table in %s must exactly have %d entries, but %s were found.", fileName, MID.max+1, messages.length));
-      GlobalSettings.messages = messages;
+      else if(v.idents[0].srcText == "lang_code")
+      {
+        auto e = v.values[0];
+        if (!e)
+          throw new Exception("lang_code variable in "~fileName~" has no value set.");
+        if (auto str = Cast!(StringLiteralsExpression)(e))
+            GlobalSettings.language = str.getString();
+      }
     }
+    if (messages.length != MID.max+1)
+      throw new Exception(std.string.format("messages table in %s must exactly have %d entries, but %s were found.", fileName, MID.max+1, messages.length));
+    GlobalSettings.messages = messages;
   }
-
 }
--- a/trunk/src/lang_de.d	Fri Aug 24 22:55:02 2007 +0000
+++ b/trunk/src/lang_de.d	Sat Aug 25 11:13:01 2007 +0000
@@ -3,6 +3,8 @@
   License: GPL3
 +/
 
+string lang_code = "de";
+
 string[] messages = [
   // Lexer messages:
   "ungültiges Unicodezeichen.",
--- a/trunk/src/lang_en.d	Fri Aug 24 22:55:02 2007 +0000
+++ b/trunk/src/lang_en.d	Sat Aug 25 11:13:01 2007 +0000
@@ -3,6 +3,8 @@
   License: GPL3
 +/
 
+string lang_code = "en";
+
 string[] messages = [
   // Lexer messages:
   "invalid Unicode character.",
--- a/trunk/src/lang_tr.d	Fri Aug 24 22:55:02 2007 +0000
+++ b/trunk/src/lang_tr.d	Sat Aug 25 11:13:01 2007 +0000
@@ -3,6 +3,8 @@
   License: GPL3
 +/
 
+string lang_code = "tr";
+
 string[] messages = [
   // Lexer messages:
   "geçersiz Unikod karakteri.",