2005-05-13 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / tools / locale-builder / CultureInfoEntry.cs
1 //
2 // Mono.Tools.LocaleBuilder.CultureInfoEntry
3 //
4 // Author(s):
5 //  Jackson Harper (jackson@ximian.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10
11 using System;
12 using System.Text;
13
14 namespace Mono.Tools.LocaleBuilder {
15
16         public class CultureInfoEntry : Entry {
17
18                 string language;
19
20                 public string Territory;
21                 public string EnglishName;
22                 public string DisplayName;
23                 public string NativeName;
24                 public string IcuName;
25                 public string Win3Lang;
26                 public string ISO2Lang;
27                 public string ISO3Lang;
28                 public string Lcid;
29                 public string ParentLcid;
30                 public string SpecificLcid;
31                 public DateTimeFormatEntry DateTimeFormatEntry;
32                 public NumberFormatEntry NumberFormatEntry;
33                 public TextInfoEntry TextInfoEntry;
34                 public int [] CalendarData = new int [5];
35                 public int DateTimeIndex;
36                 public int NumberIndex;
37                 
38                 
39                 public int Row;
40
41                 public CultureInfoEntry ()
42                 {
43                         DateTimeFormatEntry = new DateTimeFormatEntry ();
44                         NumberFormatEntry = new NumberFormatEntry ();
45                 }
46
47                 public string Language {
48                         get {
49                                 return language;
50                         }
51                         set {
52                                 language = (value == "zh") ? "zh-CHS" : value;
53                         }
54                 }
55
56                 public string Name {
57                         get {
58                                 if (Territory == null)
59                                         return Language;
60                                 return (Language.StartsWith ("zh") ? "zh" : Language) + "-" + Territory;
61                         }
62                 }
63
64                 public override string ToString ()
65                 {
66                         StringBuilder builder = new StringBuilder ();
67                         AppendTableRow (builder);
68                         return builder.ToString ();
69                 }
70
71                 public void AppendTableRow (StringBuilder builder)
72                 {
73                         builder.Append ("\t{");
74                         builder.AppendFormat ("{0}, {1}, {2}, " +
75                                         "{3}, {4}, {5}, " +
76                                         "{6}, {7}, {8}, " +
77                                         "{9}, {10}, " +
78                                         "{11}, " +
79                                         "{12}, {13}, {14}",
80                                         Lcid, ParentLcid, SpecificLcid,
81                                         EncodeStringIdx (Name), EncodeStringIdx (IcuName), EncodeStringIdx (EnglishName),
82                                         EncodeStringIdx (DisplayName), EncodeStringIdx (NativeName), EncodeStringIdx (Win3Lang),
83                                         EncodeStringIdx (ISO3Lang), EncodeStringIdx (ISO2Lang),
84                                         ValuesString (CalendarData),
85                                         DateTimeFormatEntry == null ? -1 : DateTimeFormatEntry.Row,
86                                         NumberFormatEntry == null ? -1 : NumberFormatEntry.Row,
87                                         TextInfoEntry.ToString ());
88                         builder.Append ('}');
89                 }
90
91                 private string ValuesString (int [] values)
92                 {
93                         StringBuilder builder = new StringBuilder ();
94                         builder.Append ('{');
95                         for (int i=0; i<values.Length; i++) {
96                                 builder.Append (values [i].ToString ());
97                                 if (i+1 < values.Length)
98                                         builder.Append (", ");
99                         }
100                         builder.Append ("}");
101                         return builder.ToString ();
102                 }
103         }
104         
105 }
106