国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用WindowsAPICodePack實現翻譯功能

2019-11-17 03:10:49
字體:
來源:轉載
供稿:網友

使用WindowsAPICodePack實現翻譯功能

僅限于以下幾種語言間的翻譯:

在我的另一篇博文《圖片批量壓縮》中,有介紹WindowsAPICodePack庫,該庫是微軟提供的一套基于Win7及以上版本操作系統的系統庫,可以幫助我們完成一些代碼很難完成的系統層面操作。本文就介紹其中的一個強大功能:語言的翻譯轉換功能。WindowsAPICodePack庫下載地址:官方主頁

程序界面如下:

獲取所有翻譯類別代碼:

//獲取所有翻譯類別        PRivate MappingService[] GetSpecifiedMappingServices(string CategoryName)        {            MappingService[] transliterationServices = null;            try            {                MappingEnumOptions enumOptions = new MappingEnumOptions() { Category = CategoryName };                transliterationServices = MappingService.GetServices(enumOptions);            }            catch (LinguisticException exc)            {                MessageBox.Show(exc.Message);            }            return transliterationServices;        }

  

解釋:前面貼出的可以翻譯的幾種語言,是系統給出的,并不是博主創造的,上面的代碼就是從系統中獲取所有支持的語言翻譯功能。

翻譯功能代碼如下:

private string LanguageConverter(Guid serviceGuid, string sourceContent)        {            string transliterated = null;            if ((sourceContent != null) && (sourceContent.Length > 0))            {                try                {                    MappingService mapService = new MappingService(serviceGuid);                    using (MappingPropertyBag bag = mapService.RecognizeText(sourceContent, null))                    {                        transliterated = bag.GetResultRanges()[0].FormatData(new StringFormatter());                    }                }                catch (LinguisticException exc)                {                    MessageBox.Show(exc.Message);                }            }            return transliterated;        }

  

解釋:通過serviceGuid初始化不同的翻譯器,serviceGuid就是下拉列表中選擇的語言的guid。

調用翻譯功能的代碼:

try            {                guidService = ((DataItem)comboBox1.SelectedItem).guid;                string result = LanguageConverter(guidService.GetValueOrDefault(), txtSource.Text);                if ((result != null) && (result.Length > 0))                {                    txtResult.Text = result;                }            }            catch (Exception ex)            {                MessageBox.Show(ex.Message);            }

  

解釋:略。

下載:Demo Code


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖州| 五台县| 宜兰县| 辉县市| 昭通市| 合江县| 寿阳县| 临沭县| 万载县| 永宁县| 车致| 纳雍县| 湘潭县| 应用必备| 峡江县| 同德县| 凤凰县| 浮梁县| 卓资县| 普定县| 阿拉善盟| 巴青县| 嘉峪关市| 沭阳县| 田阳县| 河南省| 长兴县| 赤峰市| 中西区| 南江县| 淮滨县| 平陆县| 江达县| 正阳县| 宜兰县| 海伦市| 宜阳县| 新昌县| 阜宁县| 土默特右旗| 上栗县|