# HG changeset patch # User aziz # Date 1188040381 0 # Node ID a0711c57c1dbf9f21fa7290518f48f9fa05d2044 # Parent 206d305b2706a6389c4485d5d30f02d1ac1a247e - 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. diff -r 206d305b2706 -r a0711c57c1db trunk/src/config.d --- 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"; diff -r 206d305b2706 -r a0711c57c1db trunk/src/dil/Settings.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; } - } diff -r 206d305b2706 -r a0711c57c1db trunk/src/lang_de.d --- 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.", diff -r 206d305b2706 -r a0711c57c1db trunk/src/lang_en.d --- 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.", diff -r 206d305b2706 -r a0711c57c1db trunk/src/lang_tr.d --- 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.",