1 /// Author: Aziz Köksal
2 /// License: GPL3
3 /// $(Maturity average)
4 module dil.i18n.ResourceBundle;
5 
6 import dil.i18n.Messages;
7 import common;
8 
9 /// Holds language-specific data (e.g. compiler messages.)
10 class ResourceBundle
11 {
12   /// The language code. E.g.: "en" for English.
13   cstring langCode;
14   /// The list of messages.
15   cstring[] messages;
16 
17   /// Constructs an object and creates a list of empty messages.
18   this()
19   {
20     this.messages = new cstring[MID.max + 1];
21   }
22 
23   /// Contructs an object and takes a list of messages.
24   this(cstring[] msgs)
25   {
26     assert(MID.max+1 == msgs.length);
27     this.messages = msgs;
28   }
29 
30   /// Contructs an object by inheriting from a parent object.
31   this(cstring[] msgs, ResourceBundle parent)
32   {
33     if (parent)
34       foreach (i, ref msg; msgs)
35         if (msg is null)
36           msg = parent.messages[i]; // Inherit from parent.
37     this(msgs);
38   }
39 
40   /// Returns a text msg for a msg ID.
41   cstring msg(MID mid)
42   {
43     return messages[mid];
44   }
45 }