2009年3月31日,微軟發佈了 Microsoft Visual Studio International Pack 1.0 SR1。Visual Studio International Pack 包含一組類庫,該類庫擴展了.NET Framework對全球化軟件開發的支持。使用該類庫提供的類,.NET 開發人員可以更方便的創建支持多文化多語言的軟件應用。下載地址是:http://www.microsoft.com/downloads/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn 該軟件包1.0版提供下面七個組件以增強.NET Framework對全球化軟件應用開發的支持。
- East Asia Numeric Formatting Library - 支持將小寫的數字字符串格式化成簡體中文,繁體中文,日文和韓文的大寫數字字符串。
- Japanese Kana Conversion Library - 支持將日文假名(Kana)轉化爲另一種日文字符。
- Japanese Text Alignment Library - 支持日文特有的一種對齊格式。
- Japanese Yomi Auto-Completion Library - 類庫支持感知日文輸入法的輸入自動完成和一個文本框控件的示例。
- Korean Auto Complete TextBox Control - 支持韓文輸入法的智能感知和輸入自動完成的文本框控件。
- Simplified Chinese Pin-Yin Conversion Library - 支持獲取簡體中文字符的常用屬性比如拼音,多音字,同音字,筆畫數。
- Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool - 支持簡繁體中文之間的轉換。該組件還包含一個Visual Studio集成開發環境中的插件(Add-in)支持簡繁體中文資源文件之間的轉換。
下載完畢後,進行解壓,裏面有7個msi文件,其中:CHSPinYinConv.msi就是漢字拼音相關的,CHTCHSConv.msi是進行簡體與繁體進行相互轉換的,值安裝這2個msi即可。安裝完畢後,需要在VS裏添加引用,分別引用:C:/Program Files/Microsoft Visual Studio International Pack/Simplified Chinese Pin-Yin Conversion Library下和C:/Program Files/Microsoft Visual Studio International Pack/Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool下的dll即可使用。下面是一個漢字“孟”的測試例子:
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.International.Converters.PinYinConverter;
using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
using System.Collections.ObjectModel;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ChineseChar chineseChar = new ChineseChar('孟');
Response.Write("<h2>關於漢字 “孟” 的相關信息:</h2>");
Response.Write("<li>“孟”筆畫數:" + ChineseChar.GetStrokeNumber('孟'));
Response.Write("<li>“孟”是否是多音字: " + chineseChar.IsPolyphone);
ReadOnlyCollection<string> pinyin = chineseChar.Pinyins;
Response.Write("<li>“孟”所有拼音:");
foreach (string pin in pinyin)
{
Response.Write(pin + ",");
}
char[] ChineseChars;
Response.Write("<li>所有拼音 MENG1 的漢字<br/>");
ChineseChars = ChineseChar.GetChars("MENG1");
Response.Write("共" + ChineseChars.Length.ToString() + "個,分別是:");
for (int i = 0; i < ChineseChars.Length; i++)
{
Response.Write(ChineseChars[i] + ",");
}
Response.Write("<li>所有拼音 MENG2 的漢字 <br/>");
ChineseChars = ChineseChar.GetChars("MENG2");
Response.Write("共" + ChineseChars.Length.ToString() + "個,分別是:");
for (int i = 0; i < ChineseChars.Length; i++)
{
Response.Write(ChineseChars[i]);
}
Response.Write("<li>所有拼音 MENG3 的漢字<br/>");
ChineseChars = ChineseChar.GetChars("MENG3");
Response.Write("共" + ChineseChars.Length.ToString() + "個,分別是:");
for (int i = 0; i < ChineseChars.Length; i++)
{
Response.Write(ChineseChars[i]);
}
Response.Write("<li>所有拼音 MENG2 的漢字<br/>");
ChineseChars = ChineseChar.GetChars("MENG4");
Response.Write("共" + ChineseChars.Length.ToString() + "個,分別是:");
for (int i = 0; i < ChineseChars.Length; i++)
{
Response.Write(ChineseChars[i]);
}
Response.Write("<li>所有拼音 MENG5 的漢字<br/>");
ChineseChars = ChineseChar.GetChars("MENG5");
Response.Write("共" + ChineseChars.Length.ToString() + "個,分別是:");
for (int i = 0; i < ChineseChars.Length; i++)
{
Response.Write(ChineseChars[i]);
}
String simText = "歡迎光臨【孟子E章】";
String traText = ChineseConverter.Convert(simText, ChineseConversionDirection.SimplifiedToTraditional);
Response.Write("<li>繁簡轉換測試:" + traText);
}
}
得到的結果是:
關於漢字 “孟” 的相關信息:
- “孟”筆畫數:8
- “孟”是否是多音字: True
- “孟”所有拼音:MENG4,MENG5,,,,,,,
- 所有拼音 MENG1 的漢字
共4個,分別是:擝,濛,矇,蒙, - 所有拼音 MENG2 的漢字
共45個,分別是:儚冡夣嫇尨幪庬懜懞掹曚朦橗檬氋氓溕濛獴甍甿盟瞢矇矒礞艨莔萌蒙蕄虻蝱鄳鄸雺霚霿靀顭饛鯍鸏鸏鼆 - 所有拼音 MENG3 的漢字
共16個,分別是:勐幪懜懵猛瓾矇艋蒙蜢蠓錳錳鯭黽鼆 - 所有拼音 MENG2 的漢字
共6個,分別是:夢夣孟懜夢霥 - 所有拼音 MENG5 的漢字
共61個,分別是:儚冡勐夢夣嫇孟尨幪庬懜懞懵掹擝曚朦夢橗檬氋氓溕濛猛獴瓾甍甿盟瞢矇矒礞艋艨莔萌蒙蕄虻蜢蝱蠓鄳鄸錳錳雺霚霥霿靀顭饛鯍鯭鸏鸏黽鼆 - 繁簡轉換測試:歡迎光臨【孟子E章】
不過:有幾個方面主要注意:
- 不清楚這個工具參照的是哪個漢字標準,SDK上也沒有看到說明,“孟”這個字在字典中並不是多音字;
- 拼音後面的1,2,3,4,5猜測應當是聲調標記:陰平,陽平,上聲,去聲,輕聲。具體是否是有待查證;
中文簡體與中文繁體之間的轉換比較簡單,下面就是一個將簡體轉換成繁體的代碼:
String traText = ChineseConverter.Convert(simText, ChineseConversionDirection.SimplifiedToTraditional);
Response.Write("<li>繁簡轉換測試:" + traText);
下面是Microsoft.International.Converters.PinYinConverter.ChineseChar類的成員:
封裝了簡體中文的讀音和筆畫等基本信息。
成員類型 | 成員 | 描述 |
---|---|---|
ChineseCharNew(Char) |
ChineseChar類的構造函數。
|
|
ChineseCharacter |
獲取這個漢字字符。
|
|
CompareStrokeNumber(Char) |
將給出的字符和實例字符的筆畫數進行比較。
|
|
靜態成員 | GetCharCount(Int16) |
檢索具有指定筆畫數的字符個數。
|
靜態成員 | GetChars(String) |
獲取給定拼音的所有同音字。
|
靜態成員 | GetChars(Int16) |
檢索具有指定筆畫數的所有字符串。
|
靜態成員 | GetHomophoneCount(String) |
檢索具有指定拼音的字符數。
|
靜態成員 | GetStrokeNumber(Char) |
檢索指定字符的筆畫數。
|
HasSound(String) |
識別字符是否有指定的讀音。
|
|
IsHomophone(Char) |
識別給出的字符是否是實例字符的同音字。
|
|
靜態成員 | IsHomophone(Char, Char) |
識別給出的兩個字符是否是同音字。
|
IsPolyphone |
獲取這個字符是否是多音字。
|
|
靜態成員 | IsValidChar(Char) |
識別給出的字符串是否是一個有效的漢字字符。
|
靜態成員 | IsValidPinyin(String) |
識別給出的拼音是否是一個有效的拼音字符串。
|
靜態成員 | IsValidStrokeNumber(Int16) |
識別給出的筆畫數是否是一個有效的筆畫數。
|
PinyinCount |
獲取這個字符的拼音個數。
|
|
Pinyins |
獲取這個字符的拼音。
|
|
StrokeNumber |
獲取這個字符的筆畫數。
|
其他信息請參與隨機安裝的chm幫助文件。