Merge pull request #5714 from alexischr/update_bockbuild
[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 using System.Collections.Generic;
14 using System.Globalization;
15
16 namespace Mono.Tools.LocaleBuilder
17 {
18         public class CultureInfoEntry : Entry
19         {
20                 string language;
21
22                 public string Script;
23                 public string Territory;
24
25                 public string EnglishName;
26                 public string DisplayName;
27                 public string NativeName;
28                 public string ThreeLetterWindowsLanguageName;
29                 public string TwoLetterISOLanguageName;
30                 public string ThreeLetterISOLanguageName;
31                 public string LCID;
32                 public string ParentLcid;
33                 public string SpecificLcid;
34                 public RegionInfoEntry RegionInfoEntry;
35                 public DateTimeFormatEntry DateTimeFormatEntry;
36                 public NumberFormatEntry NumberFormatEntry;
37                 public TextInfoEntry TextInfoEntry;
38                 public int DateTimeIndex;
39                 public int NumberIndex;
40                 public string NativeCurrencyName;
41                 public string NativeTerritoryName;
42                 public string[] NativeCalendarNames = new string[Constants.NUM_CALENDARS];
43
44                 public CalendarType CalendarType;
45                 public GregorianCalendarTypes GregorianCalendarType;
46
47                 public List<CultureInfoEntry> Children = new List<CultureInfoEntry> ();
48
49                 public int Row;
50
51                 public CultureInfoEntry ()
52                 {
53                         DateTimeFormatEntry = new DateTimeFormatEntry ();
54                         NumberFormatEntry = new NumberFormatEntry ();
55                 }
56
57                 public string Language {
58                         get {
59                                 return language;
60                         }
61                         set {
62                                 language = value;
63                         }
64                 }
65
66                 public bool HasMissingLocale { get; set; }
67
68                 public bool IsNeutral {
69                         get {
70                                 return Territory == null;
71                         }
72                 }
73
74                 public string OriginalName { get; set; }
75
76                 public CultureInfoEntry Parent { get; set; }
77
78                 public string Name {
79                         get {
80                                 string s = language;
81                                 if (Script != null)
82                                         s = s + "-" + Script;
83                                 if (Territory != null)
84                                         s = s + "-" + Territory;
85
86                                 return s;
87                         }
88                 }
89
90                 public string GetExportName ()
91                 {
92                         return OriginalName.Replace ('_', '-');
93                 }
94
95                 public override string ToString ()
96                 {
97                         StringBuilder builder = new StringBuilder ();
98                         AppendTableRow (builder);
99                         return builder.ToString ();
100                 }
101
102                 public void AppendTableRow (StringBuilder builder)
103                 {
104                         builder.Append ("\t{");
105                         builder.Append (LCID).Append (", ");
106                         builder.Append (ParentLcid).Append (", ");
107
108                         int calendar_type = (int) CalendarType;
109                         calendar_type <<= 8;
110                         if (CalendarType == CalendarType.Gregorian)
111                                 calendar_type |= (int) GregorianCalendarType;
112
113                         builder.Append (calendar_type).Append (", ");
114                         builder.Append (RegionInfoEntry == null ? -1 : RegionInfoEntry.Index).Append (", ");
115                         builder.Append (EncodeStringIdx (GetExportName ())).Append (", ");
116                         builder.Append (EncodeStringIdx (EnglishName)).Append (", ");
117                         builder.Append (EncodeStringIdx (NativeName)).Append (", ");
118                         builder.Append (EncodeStringIdx (ThreeLetterWindowsLanguageName)).Append (", ");
119                         builder.Append (EncodeStringIdx (ThreeLetterISOLanguageName)).Append (", ");
120                         builder.Append (EncodeStringIdx (TwoLetterISOLanguageName)).Append (", ");
121                         builder.Append (EncodeStringIdx (Territory)).Append (", ");
122                         AppendNames (builder, NativeCalendarNames).Append (", ");
123                         builder.Append (DateTimeFormatEntry.Row).Append (", ");
124                         builder.Append (NumberFormatEntry.Row).Append (", ");
125                         builder.Append (TextInfoEntry.ToString ());
126                         builder.Append ('}');
127                 }
128
129                 private string ValuesString (int[] values)
130                 {
131                         StringBuilder builder = new StringBuilder ();
132                         builder.Append ('{');
133                         for (int i = 0; i < values.Length; i++) {
134                                 builder.Append (values[i].ToString ());
135                                 if (i + 1 < values.Length)
136                                         builder.Append (", ");
137                         }
138                         builder.Append ("}");
139                         return builder.ToString ();
140                 }
141         }
142
143 }
144