diff mde/lookup/Translation.d @ 74:cee261eba249

Minor tweaks.
author Diggory Hardy <diggory.hardy@gmail.com>
date Mon, 07 Jul 2008 15:54:47 +0100
parents 7fc0a8295c83
children 25cb7420dc91
line wrap: on
line diff
--- a/mde/lookup/Translation.d	Mon Jul 07 15:53:58 2008 +0100
+++ b/mde/lookup/Translation.d	Mon Jul 07 15:54:47 2008 +0100
@@ -37,8 +37,8 @@
 */
 module mde.lookup.Translation;
 
-import mde.options;
-import mde.resource.paths;
+import mde.lookup.Options;
+import mde.setup.paths;
 import mde.exception;
 
 import mde.mergetag.DataSet;
@@ -59,23 +59,41 @@
     final char[] name;      /// The module/package/... which the instance is for
     final char[] L10n;      /// The localization loaded (e.g. en-GB)
     
-    /** Get the translation for the given identifier, and optionally the description.
-    * If no entry exists, the identifier will be returned. */
-    char[] getEntry (char[] id, out char[] description) {
+    alias entry opCall;	    /// Convenience alias
+    
+    /** Get the translation for the given identifier.
+    * If no entry exists, the identifier will be returned.
+    *
+    * Optionally, the description can be returned. */
+    char[] entry (char[] id) {
         Entry* p = id in entries;
-        if (p) {    // FIXME: check: a SEGFAULT?
+        if (p) {
+            return p.str;
+        } else {
+            return id;
+        }
+    }
+    /** ditto */
+    char[] entry (char[] id, out char[] description) {
+        Entry* p = id in entries;
+        if (p) {
             description = p.desc;
             return p.str;
-        } else
+        } else {
             return id;
+        }
     }
-        /** ditto */
-    char[] getEntry (char[] id) {
+    
+    /** Alternative usage: return a Translation.Entry struct. */
+    Entry getStruct (char[] id) {
         Entry* p = id in entries;
-        if (p !is null) {    // FIXME: check: a SEGFAULT?
-            return p.str;
-        } else
-            return id;
+        if (p) {
+            return *p;
+        } else {
+            Entry ret;
+            ret.str  = id;
+            return ret;
+        }
     }
     
     /** Load the translation for the requested module/package/...
@@ -174,6 +192,15 @@
     // This class is read-only and has no need of being saved.
     void writeAll (ItemDelg) {}
     
+    /** This struct is used to store each translation entry.
+     *
+     * Note that although each entry also has a version field, this is not loaded for general use.
+     */
+    struct Entry {
+        char[] str;         // The translated string
+        char[] desc;        // An optional description
+    }
+    
 private:
     /* Sets name and L10n.
     *
@@ -186,15 +213,6 @@
     //BEGIN Data
     static Logger logger;
     
-    /* This struct is used to store each translation entry.
-    *
-    * Note that although each entry also has a version field, this is not loaded for general use.
-    */
-    struct Entry {
-        char[] str;         // The translated string
-        char[] desc;        // An optional description
-    }
-    
     Entry[char[]] entries;  // all entries
     
     ID[] depends;           // dependancy sections (only used while loading)
@@ -221,15 +239,15 @@
         Translation transl = load ("i18nUnitTest");
         
         // Simple get-string, check dependancy's entry doesn't override
-        assert (transl.getEntry ("Str1") == "Test 1");
+        assert (transl.entry ("Str1") == "Test 1");
         
         // Entry included from dependancy with description
         char[] desc;
-        assert (transl.getEntry ("Str2", desc) == "Test 3");
+        assert (transl.entry ("Str2", desc) == "Test 3");
         assert (desc == "Description");
         
         // No entry: fallback to identifier string
-        assert (transl.getEntry ("Str3") == "Str3");
+        assert (transl.entry ("Str3") == "Str3");
         
         // No checks for version info since it's not functionality of this module.
         // Only check extra entries are allowed but ignored.