`
gstarwd
  • 浏览: 1539857 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Silverlight 3 with Bing Translator Services

阅读更多

I was working with one of the web application localization. I was searching with couple of translator's available with the web. The most popular of them are

1. Google Translation Service

2. Bing Translator Service

I tried using the Google API for the web and it was pretty good. Then in recent times I came across Bing translator and tools link in them gave me the way to implement the Bing API. Bing is making a revolution in the search engines and so I liked to use that here.

Following URL's are referred for this.

  1. http://www.bing.com/developers/appids.aspx
  2. http://msdn.microsoft.com/en-us/library/dd576292.aspx
  3. http://msdn.microsoft.com/en-us/library/dd877917.aspx
  4.  

Application can be downloaded from here .

Bing API:

Bing API is one of the new and cool features from Microsoft. We can use those API's for implementing the customization of search in our Application. There are three kinds of services available for us to implement.

  1. AJAX Interface
  2. HTTP
  3. SOAP

We can use the Ajax interface for our web applications. For Silverlight application it will not be so best to use them. Instead we can use the SOAP reference which will be pretty much easy. I will explain those steps below.

Create a new "Silverlight Business Application" from the templates available or a Normal application if you don't want any prebuilt customizations.

The next step is the SOAP service reference. The SOAP API path for Bing is as follows.

http://api.microsofttranslator.com/V1/SOAP.svc

Just refer this in the silverlight Application and not in the test web application which comes with the Silverlight ptoject.

Adding this creates all the proxy files needed to work with. The next thing is the Application key. This we can get free from the Bing developer website which is given below. One needs to have a Hotmail ID to get this done.

http://www.bing.com/developers/appids.aspx

Through this link we have to create an AppId which we will be using all around the SOAP calls as this is used to give sandboxing security. Since we have taken the Silverlight Navigation Application we will use the HomePage.Xaml to give all the updates and testing. I will explain the cod below.

 

TranslatorService.LanguageServiceClient ls=new LanguageServiceClient ();// Creating Bing SOAP Ref object

string AppId = "8ABC484831F80ABC46C07CBFF2C34FF7884A4168" ;// This AppId is created for my name

System.Collections.ObjectModel.ObservableCollection <string > results;

System.Collections.ObjectModel.ObservableCollection <string > langcodes;

 

This code block has to be declared at the page level .LanguageServiceClient is the Class which has all the methods needed to do the translation. Hence we will create instance at the page level and use that wherever needed. The ApplicationId will be used in all the calls. We can configure this at the configuration level. For now I have given this at the Page level. The result groups that are returned from the SOAP calls are in the form of ObservableCollection .

The XAML structure I very simple for now. We have source language and destination language which we can populate with the GeLangaugeNames method from SOAP calls. The textboxes are used to display source text and destination text.

< StackPanel Style ="{ StaticResource ContentTextPanelStyle }">

< controls : Label Content ="Language Source"></ controls : Label >

< ComboBox x : Name ="src"></ ComboBox >

< controls : Label Content ="Destination"></ controls : Label >

< ComboBox x : Name ="dest"></ ComboBox >

</ StackPanel >

< StackPanel Style ="{ StaticResource ContentTextPanelStyle }">

< TextBlock > Text to translate </ TextBlock >

< TextBox x : Name ="srcTxt" Width ="100"></ TextBox >

< TextBox x : Name ="destTxt" Width ="100"></ TextBox >

< Button x : Name ="cmdSubmit" Click ="cmdSubmit_Click" Width ="50" Content ="Submit"></ Button >

</ StackPanel >

 

The silverlight calls the webservices in Asynchronous Modes only. Hence we need to handle the events to fetch the values. We have to get the results inside those event definitions. Following are the delegate for event's which we can give in the Page load event. Also we have to call the dropdown load events to load the languages.

//Event Handlers

ls.TranslateCompleted +=new EventHandler <TranslateCompletedEventArgs >(ls_TranslateCompleted);

ls.GetLanguageNamesCompleted +=new EventHandler <GetLanguageNamesCompletedEventArgs >(ls_GetLanguageNamesCompleted);

ls.GetLanguagesCompleted +=new EventHandler <GetLanguagesCompletedEventArgs >(ls_GetLanguagesCompleted);

//For filling the dropdown's and Language codes

ls.GetLanguageNamesAsync(AppId,this .Language.IetfLanguageTag);

ls.GetLanguagesAsync(AppId);

 

//Get the translated text

protected void ls_TranslateCompleted(Object sender,TranslateCompletedEventArgs e){

if (e.Error == null ){

destTxt.Text = e.Result;

}

}

 

//Get Languages

protected void ls_GetLanguagesCompleted(object sender, GetLanguagesCompletedEventArgs e) {

if (e.Error == null ) {

langcodes = e.Result;

}

}

 

//Fill the dropdown's

protected void ls_GetLanguageNamesCompleted(Object sender, GetLanguageNamesCompletedEventArgs e)

{

if (e.Error == null )

{

results = e.Result;

this .src.ItemsSource = results;

this .dest.ItemsSource = results;

}

}

 

private void PerformTranslation() {

if (src.SelectedItem != null && dest.SelectedItem != null )

{

ls.TranslateAsync(AppId, srcTxt.Text, (langcodes[src.SelectedIndex].ToString()), (langcodes[dest.SelectedIndex].ToString()));

}

}

//Translate on button click

private void cmdSubmit_Click(object sender, RoutedEventArgs e)

{

PerformTranslation();

}

 

The final output will be like as follows.

Application can be downloaded from here .

Conclusion:

The translation so far tried is working fine. The Google service is providing more languages that this. In few months Microsoft will release those language features also. We can expect that. There is one more feature called Transliteration available in Google service. I Bing also give that then it will be so nice. Readers can also refer to how the Ajax and HTTP are used. The same code may also work for web application other than Asynchronous mode which is for Silverlight.

分享到:
评论

相关推荐

    在Twitter上禁用必应翻译器「Disable Bing Translator on Twitter」-crx插件

    通过在Twitter上出现...但是,它不会在您的Twitter帐户上禁用Bing Translator,因为Twitter到目前为止尚未提供此类选项。 http://www.thelacunablog.com/disable-bing-translator-twitter.html 支持语言:English (UK)

    bing_translator-gem:Bing翻译API的简单Ruby接口

    该gem包装了Microsoft Cognitive Services Translator API。 安装 要使用此宝石Ruby,请执行以下操作: $ sudo gem install bing_translator 使用捆绑器: gem "bing_translator", "~&gt; 6.1.0" 信息 Microsoft ...

    Python库 | deep_translator-1.0.2-py2.py3-none-any.whl

    此库的核心功能是提供多种在线翻译引擎的接口,包括Google Translate、Microsoft Translator、Yandex.Translate、Bing Translator等。开发者可以通过调用这些接口,轻松地将文本从一种语言翻译成另一种语言。这对于...

    ms-translator:使用 Microsoft Bing Translate API 翻译文本

    ms-translator 使用 Bing Translate API 翻译文本##操作说明使用 Microsoft 的必应翻译服务 HTTP API 翻译您的文本该代码基于 Microsoft 在文档中提供的代码,为 Composer 准备。 在两行中,您可以让翻译服务工作...

    Translator2 Translator2

    3. **实时翻译**:在线编辑器功能允许用户直接输入文本并实时查看翻译结果,方便快捷。 4. **格式保持**:翻译后的文本能保留原文的格式和排版,对于文档翻译尤其重要,确保转换后的文件易于阅读和编辑。 5. **...

    Python库 | bing_translation_for_python-3.0.0-py3-none-any.whl

    `bing_translation_for_python-3.0.0-py3-none-any.whl` 是一个针对Python开发的库,它提供了与微软Bing翻译服务交互的能力。这个库使Python开发者能够轻松地在他们的应用中集成自动翻译功能,支持多种语言之间的...

    bing翻译APIDemo Soap接口

    【标签】中的"Translator"是指翻译功能,"Bing翻译"是微软提供的在线翻译服务,支持多种语言的自动翻译。"Bing"则是微软的搜索引擎,同时也提供了包括翻译在内的各种Web服务。 在【压缩包子文件的文件名称列表】中...

    Pads Translator 2005

    《Pads Translator 2005:Protel到Pads的高效转换工具》 在电子设计领域,Protel和Pads是两种广泛使用的电路设计软件。Protel以其易用性和全面的功能深受工程师喜爱,而Pads则以其高效的布线能力和强大的后处理功能...

    Microsoft Translator Custom Translator User GuideV3

    3. **Microsoft Translator API**: - 微软翻译器API是应用编程接口,允许开发者访问和使用微软翻译器服务。 - 用户可以利用定制的翻译系统通过Microsoft Translator Text API访问翻译。 4. **神经机器翻译**: ...

    Translator2日语词典免费

    3. **生词本**:用户可以收藏不熟悉的词汇,便于日后复习和巩固。 4. **学习模式**:可能设有单词卡片、听力训练等学习模块,提高用户的语言听说能力。 5. **离线使用**:作为绿色软件,可能支持离线翻译,无需网络...

    基于microsoftTranslator实现js中英文切换

    3. 处理响应:API返回翻译结果后,解析JSON响应,提取翻译后的文本。 4. 更新页面:遍历页面上的元素,根据元素的`data-lang`或者其他自定义属性,判断是否需要更新其文本内容。 5. 事件监听:添加一个语言切换按钮...

    translate-shell:使用Google Translate,Bing Translator,Yandex.Translate等的命令行翻译器

    翻译外壳 (以前称为Google Translate CLI )是由 (默认), , 和支持的命令行翻译器。 它使您可以轻松访问终端中的以下翻译引擎之一: $ trans 'Saluton, Mondo!' Saluton, Mondo! Hello, World!...

    Laravel开发-translator

    `Laravel开发-translator`是一个针对这一需求的解决方案,它提供了一个灵活的翻译工具,能够基于`.csv`语言文件进行翻译。这种工具使得开发者可以更方便地管理和维护项目的多语言内容。 在Laravel中,本地化是通过`...

    Translator++ 增加百度翻译api

    百度翻译api使用的是 http://api.fanyi.baidu.com/doc/21 的接口。将js文件放入Translator++安装目录下的www\js\autoload\目录就可以配置使用了。appid与密钥需要自己去申请获取。

    Laravel开发-laravel5-translator

    在本文中,我们将深入探讨基于Laravel框架的"Laravel5-Translator"项目,这是一个增强型的翻译管理工具,专为Laravel 5设计。Laravel是PHP领域内一个流行的、优雅的Web应用框架,它提供了丰富的功能和工具,使得...

    基于microsoftTranslator实现js中英文转换

    微软的Microsoft Translator API 提供了这样的服务,它允许开发者通过API调用来完成不同语言之间的翻译工作,包括中文和英文。在这个项目中,我们将深入探讨如何利用Microsoft Translator API在JavaScript中实现实时...

    GoogleTranslator

    GoogleTranslator.rar google翻译软件

    Python库 | deep_translator-1.1.3-py2.py3-none-any.whl

    资源分类:Python库 所属语言:Python 资源全名:deep_translator-1.1.3-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Laravel开发-laravel.translator

    3. **多层结构**:除了基本的键值对,可能还支持更复杂的多级键,使得组织和管理大量的翻译内容更加有序。 4. **自动检测用户语言**:根据用户的浏览器设置或用户首选项,自动选择合适的语言。 5. **接口友好**:...

    CopyTranslator复制即翻译 v11.0.0.zip

    "CopyTranslator复制即翻译 v11.0.0.zip" 是一个软件压缩包,其中包含的是 CopyTranslator 的 v11.0.0 版本。CopyTranslator 是一款实用的翻译工具,尤其对于程序员和IT专业人士来说,它提供了一种高效的方式来翻译...

Global site tag (gtag.js) - Google Analytics