Thursday, September 8, 2011

Micro Soft API For Language Converter(Englsih to Chinise)

microsoft provides API service for the language converter. using this you can convert one language to other languae. Here I am putting the code for converting the English words to chinese words. If you want to convert any other language to any other languae you can also achive this. Because microsoft bing translator provides a lot of languges support and enhanceing the translating power day by day.






References :- http://www.microsoft.com/web/post/using-the-free-bing-translation-apis


To get your Bing App ID, visit http://www.bing.com/developers/appids.aspx, and sign in with your Windows Live ID
Before using the above code include the following name spaces:




using System.Net;
public string micorsoftApi(string wordToBeTranslate)
{
//Creating the object of proxy
WebProxy p = new WebProxy();
//crating nexwork crediential
NetworkCredential nc = new NetworkCredential("NetworkOrSystemUserId", "NetWorkOrSystemPassword", "YourNetWorkDomainName");
string proxyURL=”put the URL of your Network proxy”
p = new WebProxy(proxyURL, true, null, nc);
//setting applicaiton Id Bing translator appId change the application //id according to applicaiton you get the the application id for the //perticuler URL after registed that site on Bing BD
string appId = "xyz";//Get API ID by registed on bing and put here
string tobetranslated = wordToBeTranslate.Trim();
//setting from language parameter en for english
string fromLang =”en”;
//settting to language parameter zh-CHT for chainis traditional and //zh-CHS for chinise simplified
string toLang =”zh-CHS”;
string translatedText = string.Empty;
string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId="+ appId + "&text=" + tobetranslated + "&from=" + fromLang + "&to=" + toLang;
//creating object and of webrequest
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//setting proxy and network credentials to web request
request.Proxy = p;
request.Credentials = nc;
//geting the response from bing appi
WebResponse response = request.GetResponse();
//reading the the data form response as stream
Stream strm = response.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
translatedText = reader.ReadToEnd();
//wriint the converted text into chinise
Response.Write("The translated text is: '" + translatedText + "'.");
// lbl.Text = "The translated text is: '" + translatedText + "'.";
response.Close();
return translatedText;




}


Other Refrences:-
http://sdk.microsofttranslator.com/
http://www.microsofttranslator.com/mix2010/
http://www.microsofttranslator.com/
http://www.microsofttranslator.com/dev/


Hope this code will help all of you.


Jai Durga Ji Ki
Praveen Kumar Singh Bisen

UDF for splite string in Sql Server

/****** Object: UserDefinedFunction [dbo].[fnStringSplitter] Script Date: 09/08/2011 12:42:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--select * from LoungeAccessHistory where CardNumber like '55%'


/*******************************************************************************************************/
-- Author: Praveen Kumar Sing Bisen
-- Date: 29/8/2011 /*******************************************************************************************************/
Create Function [dbo].[fnStringSplitter]
(
@IDs Varchar(max), --A big string which may have delimeter in it or not
@Delimiter Varchar(1) -- Delimeter to use for splitting up the given string
)
/*********************** RETURN *********************/
--Returns the table with specific values in a temporary table. Useful especially if you have any IDs in the
--given string and want to get them as a table row values.
-- Example:
--@IDs = 1,2,3,4,5,6,7,8,9,10
--@Delimeter = ','
--Returns @Tbl_IDS, which is having 10 rows with above IDS in each row by splitting up with given delimeter [in this example ',']
/****************************************************/
Returns @Tbl_IDs Table (ID Varchar(500)) As
Begin
--Remove the leading delimiter if any
while (substring(@IDs,1,1) =@Delimiter)
set @IDs = substring(@IDs, 2,len(@IDs)-1)

-- Append comma
Set @IDs = @IDs + @Delimiter

-- Indexes to keep the position of searching
Declare @Pos1 Int
Declare @pos2 Int
Declare @RowNum Int

-- Start from first character
Set @Pos1=1
Set @Pos2=1
While @Pos1 Begin
Set @Pos1 = CharIndex(@Delimiter,@IDs,@Pos1)
Insert @Tbl_IDs Values (Substring(@IDs,@Pos2,@Pos1-@Pos2))
-- Go to next non comma character
Set @Pos2=@Pos1+1
-- Search from the next charcater
Set @Pos1 = @Pos1+1
End
Return
End

Procedure to send the Mail using SqlServer


We can use this procedure to send the mail from backend

create Procedure sp_SendMail   
 @mailBody varchar(8000),   
 @mailSubject varchar(2000),   
 @mailTo varchar(max),   
 @mailCCList varchar(max)   
As   
 --Set the profile name   
 Declare @emailProfileName as nvarchar(50)   
 select @emailProfileName=[value] from SystemConfig where [Name]='SenderAccountProfileName'   
   
 --configure mail profile if not already there   
 if Not Exists(SELECT profile_id, * FROM msdb.dbo.sysmail_profile WHERE name =@emailProfileName)   
  exec ConfigureMail   
   
   
 --Send Email   
 if(Len(RTrim(@mailTo)))>0   
 begin   
  EXEC msdb.dbo.sp_send_dbmail    
   @profile_name = @emailProfileName,   
   @recipients = @mailTo,   
    @copy_recipients = @mailCCList, 
   @subject = @mailSubject,   
   @body = @mailbody,   
   @body_format = 'HTML' ;   
 end