Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /RsiEditor/Lang.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations) (download)
Fri Jun 4 08:26:57 2010 UTC (13 years, 10 months ago) by pex
File size: 6453 byte(s)


1 pex 3 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using System.Collections;
5    
6     namespace RipSync.RsiEditor
7     {
8     /// <summary>
9     /// 多言語対応クラス。
10     /// </summary>
11     public class Lang
12     {
13     private string[] pofilename;
14     private int _selectindex;
15     private Hashtable mjhMSG = new Hashtable();
16    
17     /// <summary>
18     /// コンストラクタ。
19     /// </summary>
20     /// <param name="_filename"></param>
21     public Lang()
22     {
23     //*.poのリスト取得
24     pofilename = System.IO.Directory.GetFiles(System.Windows.Forms.Application.StartupPath, "*.po");
25     }
26    
27     /// <summary>
28     /// poファイルの一覧を取得する。
29     /// </summary>
30     public string[] GetPofileList
31     {
32     get
33     {
34     return pofilename;
35     }
36     }
37     /// <summary>
38     /// 選択された言語
39     /// </summary>
40     public int SelectIndex
41     {
42     get
43     {
44     return _selectindex;
45    
46     }
47     set
48     {
49     _selectindex = value;
50     }
51     }
52    
53    
54    
55     /// <summary>
56     /// メッセージの読み込み
57     /// </summary>
58     public void Load()
59     {
60     string strLine = "";
61     string firststr = "";
62     string strkey = "";
63     string strval = "";
64    
65     //指定された言語のpoファイルをオープン
66     System.IO.StreamReader sr = new System.IO.StreamReader(pofilename[_selectindex], Encoding.GetEncoding("UTF-8"));
67    
68     mjhMSG.Clear();
69     //ファイル終端までループ
70     strLine = sr.ReadLine();
71     while (sr.EndOfStream == false)
72     {
73     if (strLine.IndexOf(" ") > 0)
74     {
75     //最初の空白までの単語を取得
76     firststr = strLine.Substring(0, strLine.IndexOf(" "));
77     //行の内容で分岐
78     switch (firststr)
79     {
80     //キー(日本語表記)
81     case "msgid":
82     strkey = strLine.Substring(firststr.Length + 1);
83     if (strkey == "\"\"")
84     {
85     // 複数行に渡る場合
86     strkey = strkey.Replace("\"", "");
87     //次の行を読み込み
88     strLine = sr.ReadLine();
89     //左端が"の間繰り返す
90     while (strLine.Length > 0 && strLine.Substring(0, 1) == "\"")
91     {
92     strLine = strLine.Replace("\"", "");
93     strLine = strLine.Replace("\\n", "\n");
94     strkey = strkey + strLine;
95     strLine = sr.ReadLine();
96     }
97     }
98     else
99     {
100     //不要文字カット
101     strkey = strkey.Replace("\"", "");
102     strLine = sr.ReadLine();
103     }
104     break;
105    
106     //値(指定言語)
107     case "msgstr":
108     strval = strLine.Substring(firststr.Length + 1);
109     if (strval == "\"\"")
110     {
111     // 複数行に渡る場合
112     strval = strval.Replace("\"", "");
113     //次の行を読み込み
114     strLine = sr.ReadLine();
115     //左端が"の間繰り返す ※poファイルヘッダ情報を読むとき読み込み続けるけど無視w
116     while (strLine.Length > 0 && strLine.Substring(0, 1) == "\"")
117     {
118     strLine = strLine.Replace("\"", "");
119     strLine = strLine.Replace("\\n", "\n");
120     strval = strval + strLine;
121     strLine = sr.ReadLine();
122     }
123     }
124     else
125     {
126     //1行の場合:不要文字カット
127     strval = strval.Replace("\"", "");
128     strLine = sr.ReadLine();
129     }
130     if (strkey.Length > 0)
131     {
132     mjhMSG.Add(strkey, strval);
133     strkey = "";
134     strval = "";
135     }
136     break;
137    
138     default:
139     //読み飛ばし
140     strLine = sr.ReadLine();
141     break;
142     } //switch (firststr)
143     }
144     else
145     {
146     //読み飛ばし
147     strLine = sr.ReadLine();
148     }
149    
150     } // while (sr.EndOfStream == false)
151    
152     sr.Close();
153     }
154    
155    
156     /// <summary>
157     /// メッセージの取得
158     /// </summary>
159     public string getMessage(string key)
160     {
161     try
162     {
163     // メッセージのハッシュテーブルから検索
164     string wk = mjhMSG[key].ToString();
165    
166     // あればその内容を返す
167     if (wk != "")
168     {
169     return wk;
170     }
171     else
172     {
173     // 無ければkeyを返す
174     return key;
175     }
176     }
177     catch
178     {
179     // 無ければkeyを返す
180     return key;
181     }
182    
183     }
184    
185    
186     }
187     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26