<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MSCRM Blogger &#187; Addons</title>
	<atom:link href="http://mscrmblogger.com/category/addons/feed/" rel="self" type="application/rss+xml" />
	<link>http://mscrmblogger.com</link>
	<description>Achieving it all with Microsoft Dynamics CRM™</description>
	<lastBuildDate>Thu, 10 May 2012 20:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Use Microsoft Translator to translate text in CRM (Button on Ribbon)</title>
		<link>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/</link>
		<comments>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 15:58:19 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Addons]]></category>
		<category><![CDATA[API-SDK]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[General API Usage]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[bing translator]]></category>
		<category><![CDATA[cases]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 2011]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics crm]]></category>
		<category><![CDATA[Microsoft Dynamics CRM 2011]]></category>
		<category><![CDATA[microsoft translator]]></category>
		<category><![CDATA[ribbon]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[translate]]></category>
		<category><![CDATA[Web Resource]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=695</guid>
		<description><![CDATA[Ever want to translate text from within CRM?  This solution adds a button on the ribbon to translate text from other languages to english using the Microsoft Bing Translator.]]></description>
			<content:encoded><![CDATA[<p>Do you have issues receiving request or information in various languages and need it translated to English (or another language)?  I found the need to translate something from any language to english just so when someone submits a case or puts some notes in another language it can quickly be translated.</p>
<p>Here is what my bing translator integration looks like.</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/translator-screenshot.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/translator-screenshot.png" alt="" title="Implemented Translator Screenshot" width="730" height="671" class="aligncenter size-full wp-image-706" /></a></p>
<p>You can download an unmanaged solution to implement the bing translator for cases, letters, tasks, and emails, you can download it here: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0.zip'>Translate_1_0.zip</a>.  It will not modify your forms, but if you have unmanaged ribbon buttons on those entities, it will remove them.  So to avoid that problem you can install <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-ImageJS.zip'>the unmanaged solution with the JScript (that you need to edit to set your bing api key) and the images</a>, and then follow the RibbonDiff guide in the SDK to add the buttons, or install <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-Ribbon-Managed.zip'>the managed solution</a> to add the button to the ribbons for cases, letters, tasks, and emails.</p>
<p>To start, I created a JScript file to include as a web-resource that I could leverage when a button is clicked on the ribbon.  This JScript file utilizes the Bing Translation WebServices to translate text.</p>
<p><i><b>YOU WILL NEED TO EDIT THE JSCRIPT FILE AND CHANGE &#8216;YOUR API KEY GOES HERE&#8217; TO CONTAIN YOUR API KEY.</b></i></p>
<pre name="code" class="javascript">
var bing = {};
bing.popup = {};
bing.language = {};

bing.appId = 'YOUR API KEY GOES HERE';
bing.language.text = '';
bing.language.from = '';
bing.language.to = 'en';

bing.language.detect = function (text,oncomplete)
{
  var src = &quot;https://api.microsofttranslator.com/V2/Ajax.svc/Detect?oncomplete=&quot; +
      oncomplete + &quot;&amp;appId=&quot;+ bing.appId + &quot;&amp;text=&quot; + text;
  var s = document.createElement(&quot;script&quot;);
  s.src = src;
  s.id = &quot;bingdetect&quot;;
  document.getElementsByTagName(&quot;head&quot;)[0].appendChild(s);
}

bing.language.translate = function(from,to,text,oncomplete)
{
  var src = &quot;https://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=&quot; +
      oncomplete + &quot;&amp;appId=&quot; + bing.appId + &quot;&amp;from=&quot; + from +
      &quot;&amp;to=&quot; + to + &quot;&amp;text=&quot; + text;

  var s = document.createElement(&quot;script&quot;);
  s.src = src;
  s.id = &quot;bingtranslate&quot;;
  document.getElementsByTagName(&quot;head&quot;)[0].appendChild(s);
}

bing.popup.show = function(text)
{
  var idiv = document.createElement('div');
  idiv.id = &quot;bingtext&quot;;
  idiv.style.height = &quot;265px&quot;;
  idiv.style.width = &quot;306px&quot;;
  idiv.style.align = &quot;left&quot;;
  idiv.style.textAlign = &quot;left&quot;;
  idiv.style.backgroundColor = &quot;white&quot;;
  idiv.style.overflow = &quot;auto&quot;;
  idiv.style.padding = &quot;2px&quot;;
  idiv.style.margin = &quot;2px&quot;;
  idiv.style.border = &quot;1px solid black&quot;;
  idiv.innerHTML =  &quot;&lt;p&gt;&quot;+text+&quot;&lt;/p&gt;&quot;;

  var iurl = Xrm.Page.context.getServerUrl();
  iurl += &quot;WebResources/tran_img/translatelogo.gif&quot;;

  var img = document.createElement('img');
  img.src = iurl;

  var div = document.createElement('div');
  div.id = &quot;bingpopup&quot;;
  div.appendChild(img);
  div.appendChild(idiv);
  div.innerHTML += &quot;&lt;button style='text-align:center;width:60px;' onclick='bing.popup.copy();'&gt;Copy&lt;/button&gt;&amp;nbsp;&amp;nbsp;&quot;;
  div.innerHTML += &quot;&lt;button style='text-align:center;width:60px;' onclick='bing.popup.hide();'&gt;Close&lt;/button&gt;&quot;;
  div.style.position = &quot;absolute&quot;;
  div.style.backgroundColor = &quot;#20415F&quot;;
  div.style.border=&quot;1px solid black&quot;;
  div.style.left = &quot;50%&quot;;
  div.style.top = &quot;50%&quot;;
  div.style.color = &quot;black&quot;;
  div.style.padding = &quot;5px&quot;;
  div.style.width = &quot;320px&quot;;
  div.style.height = &quot;340px&quot;;
  div.style.marginLeft = &quot;-160px&quot;;
  div.style.marginTop = &quot;-170px&quot;;
  div.setAttribute(&quot;align&quot;,&quot;center&quot;);
  document.getElementsByTagName(&quot;body&quot;)[0].appendChild(div);
}

bing.popup.hide = function()
{
  var deleteElement = function(id) {
    var el = document.getElementById(id);
    el.parentNode.removeChild(el);
  }

  deleteElement(&quot;bingpopup&quot;);
  deleteElement(&quot;bingdetect&quot;);
  deleteElement(&quot;bingtranslate&quot;);
}

bing.popup.copy = function()
{
  var el = document.getElementById('bingtext');

  if (window.clipboardData &amp;&amp; window.clipboardData.setData)
  {
    window.clipboardData.setData(&quot;Text&quot;, el.innerText);
  }
}

bing.getSelectedText = function (p)
{
  if (p.getSelection)
  {
    text = p.getSelection();
  }
  else if (p.selection)
  {
    text = p.selection.createRange().text;
  }
  return text;
}

// get current control
bing.language.toolbarClick = function (ctrl)
{
  var text = '';
  if (window.getSelection)
  {
    text = window.getSelection();
  }
  else {
    text = bing.getSelectedText(document);
  }

  if (text==null || text=='') {
    if (ctrl==null) {
      ctrl = Xrm.Page.ui.getCurrentControl();
    }

    var entityName = Xrm.Page.data.entity.getEntityName();
    if (ctrl==null &amp;&amp; entityName.match(/letter|email|task/)) {
      ctrl = Xrm.Page.ui.controls.get('description');
    }

    if (ctrl==null) {
      alert('Please highlight the text to translate.');
      return;
    }

    if (ctrl.getControlType()!=&quot;standard&quot;) {
      return; // only standard
    }

    if (ctrl.getName()==&quot;notescontrol&quot;) {
      text = bing.getSelectedText(document.frames['notescontrol'].document);
      if (text==null || text == &quot;&quot;) {
        alert('Please highlight the text to translate.');
      }
    }

    if (text == null || text == &quot;&quot;) {
      var attr = ctrl.getAttribute();
      if (attr!=null) {
        var t = attr.getAttributeType();
        if (t.match(/string|memo/))
        {
          text = attr.getValue();
        }
      }
    }
  }

  if (text == null || text == &quot;&quot;) {
    // Nothing to translate
    return;
  }  

  text = encodeURIComponent(text);
  bing.language.text = text;

  bing.language.from = '';
  bing.language.detect(text,&quot;translate&quot;);
}

window.translate = function (response)
{
  bing.language.from = response;
  bing.language.translate(bing.language.from,bing.language.to,bing.language.text,&quot;translated&quot;);
}

window.translated = function (response)
{
  bing.popup.show(response);
}
</pre>
<p>The JScript uses the Bing Translate logo image (WebResources/tran_img/translatelogo.gif &#8211; you may need to change the path in the JScript):</p>
<p><a href="http://mscrmblogger.com/wp-content/uploads/2011/09/bingtranslatelogo.gif"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/bingtranslatelogo.gif" alt="" title="Bing Translator Logo" width="145" height="39" class="aligncenter size-full wp-image-700" /></a></p>
<p>I added some images for Microsoft Translate button images:</p>
<p><center></p>
<table style="background-color:white;padding:20px;color:black">
<tr>
<td style="border:1px solid black;height:65px;padding:7px;">
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_16x16.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_16x16.png" alt="" title="tran_icontranslate_16x16" width="16" height="16" /></a><br />16&#215;16 image<br />tran_icontranslate_16x16.png
</td>
<td style="width:20px" />
<td style="border:1px solid black;height:65px;padding:7px;">
<a href="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_32x32.png"><img src="http://mscrmblogger.com/wp-content/uploads/2011/09/tran_icontranslate_32x32.png" alt="" title="tran_icontranslate_32x32" width="32" height="32" /></a><br />32&#215;32 image<br />tran_icontranslate_32x32.png
</td>
</tr>
</table>
<p>
</center></p>
<p>Then I added the buttons to the ribbons on the entities I wanted to have bing translation capabilities by following the <a href="http://msdn.microsoft.com/en-us/library/gg334341.aspx">SDK guidelines to add a button</a>.  Here is the RibbonDiffXml for a case.  You can follow the guide to change it to be on different entities.</p>
<pre name="code" class="xml">
&lt;RibbonDiffXml&gt;
  &lt;CustomActions&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Groups._children&quot;
                  Sequence=&quot;110&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;Group Id=&quot;bing.incident.form.Bing.Group&quot;
             Command=&quot;bing.incident.form.Bing.Command&quot;
             Title=&quot;$LocLabels:bing.incident.Bing.Title&quot;
             Sequence=&quot;39&quot;
             Template=&quot;Mscrm.Templates.Flexible2&quot;
             Image32by32Popup=&quot;$webresource:tran_icon/translate_32x32.png&quot;&gt;
      &lt;Controls Id=&quot;bing.incident.form.Bing.Controls&quot;&gt;
        &lt;Button Id=&quot;bing.incident.form.Bing.Button.BingTranslator&quot;
                Command=&quot;bing.incident.Bing.Button.BingTranslator.Command&quot;
                Sequence=&quot;10&quot;
                LabelText=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.LabelText&quot;
                ToolTipTitle=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.LabelText&quot;
                ToolTipDescription=&quot;$LocLabels:bing.incident.Bing.Button.BingTranslator.Description&quot;
                TemplateAlias=&quot;isv&quot;
                Image16by16=&quot;$webresource:tran_icon/translate_16x16.png&quot;
                Image32by32=&quot;$webresource:tran_icon/translate_32x32.png&quot; /&gt;
      &lt;/Controls&gt;
      &lt;/Group&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.Popup.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Scaling._children&quot;
                  Sequence=&quot;140&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;Scale Id=&quot;bing.incident.form.Bing.Popup.1&quot;
             GroupId=&quot;bing.incident.form.Bing.Group&quot;
             Sequence=&quot;85&quot;
             Size=&quot;Popup&quot; /&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
    &lt;CustomAction Id=&quot;bing.incident.form.Bing.MaxSize.CustomAction&quot;
                  Location=&quot;Mscrm.Form.incident.MainTab.Scaling._children&quot;
                  Sequence=&quot;120&quot;&gt;
    &lt;CommandUIDefinition&gt;
      &lt;MaxSize Id=&quot;bing.incident.form.Bing.MaxSize&quot;
               GroupId=&quot;bing.incident.form.Bing.Group&quot;
               Sequence=&quot;21&quot;
               Size=&quot;LargeLarge&quot; /&gt;
    &lt;/CommandUIDefinition&gt;
    &lt;/CustomAction&gt;
  &lt;/CustomActions&gt;
  &lt;Templates&gt;
    &lt;RibbonTemplates Id=&quot;Mscrm.Templates&quot;&gt;&lt;/RibbonTemplates&gt;
  &lt;/Templates&gt;
  &lt;CommandDefinitions&gt;
    &lt;CommandDefinition Id=&quot;bing.incident.Bing.Button.BingTranslator.Command&quot;&gt;
    &lt;EnableRules /&gt;
    &lt;DisplayRules /&gt;
    &lt;Actions&gt;
      &lt;JavaScriptFunction Library=&quot;$webresource:tran_js/bing.translate.js&quot;
                          FunctionName=&quot;bing.language.toolbarClick&quot;&gt;
      &lt;CrmParameter Value=&quot;SelectedControl&quot; /&gt;
      &lt;/JavaScriptFunction&gt;
    &lt;/Actions&gt;
    &lt;/CommandDefinition&gt;
    &lt;CommandDefinition Id=&quot;bing.incident.form.Bing.Command&quot;&gt;
    &lt;EnableRules&gt;&lt;/EnableRules&gt;
    &lt;DisplayRules /&gt;
    &lt;Actions /&gt;
    &lt;/CommandDefinition&gt;
  &lt;/CommandDefinitions&gt;
  &lt;RuleDefinitions&gt;
    &lt;TabDisplayRules /&gt;
    &lt;DisplayRules /&gt;
    &lt;EnableRules /&gt;
  &lt;/RuleDefinitions&gt;
  &lt;LocLabels&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Title&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Bing&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Button.BingTranslator.LabelText&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Translate&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
    &lt;LocLabel Id=&quot;bing.incident.Bing.Button.BingTranslator.Description&quot;&gt;
    &lt;Titles&gt;
      &lt;Title languagecode=&quot;1033&quot;
             description=&quot;Translate text area with bing!&quot; /&gt;
    &lt;/Titles&gt;
    &lt;/LocLabel&gt;
  &lt;/LocLabels&gt;
&lt;/RibbonDiffXml&gt;
</pre>
<p>Here are the files to download if you want to use it:</p>
<ul>
<li>Option A
<ul>
<li>Complete unmanaged solution: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0.zip'>Translate_1_0.zip</a></li>
</ul>
</li>
<li>Option B
<ul>
<li>Unmanaged Image and JScript solution: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-ImageJS.zip'>Translate_1_0-ImageJS.zip</a>
<ul>
<li>You will need to edit the JScript to set your Bing API key.</li>
</ul>
</li>
<li>Managed Solution for the Ribbons on cases, letters, tasks, and emails: <a href='http://mscrmblogger.com/wp-content/uploads/2011/09/Translate_1_0-Ribbon-Managed.zip'>Translate_1_0-Ribbon-Managed.zip</a></li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2011/09/14/use-microsoft-translator-to-translate-text-in-crm-button-on-ribbon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

