Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
TrayStatus
VoiceBot
WallpaperFusion
Clipboard
Fusion
by Binary Fortress Software
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
Features
Features
HotKeys
Macros
Triggers
Clipboard Syncing
Clipboard Manager
Languages
Free vs Pro
Apps
More
Screenshots
Macros
Languages
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Purchase
Login / Register
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
Google Translation API
Return to ClipboardFusion Macros
Description
This script translates any text it receives into English using Google Translate. You'll need Newtonsoft.Json.dll from the net45 folder in the script references for this to work.
Language
C#.net
Minimum Version
5.3+
Created By
Thomas Malloch (BFS)
Contributors
-
Date Created
May 8, 2018
Date Last Modified
May 8, 2018
Macro Code
Copy
Select All
using System; using System.Collections.Generic; using Newtonsoft.Json; using System.Text; using System.IO; using System.Net; using Newtonsoft.Json.Linq; // The 'text' parameter will contain the text from the: // - Current Clipboard when run by HotKey // - History Item when run from the History Menu // The returned string will be: // - Placed directly on the Clipboard // - Ignored by ClipboardFusion if it is 'null' public static class ClipboardFusionHelper { //put your google api key here //you can find out how to her on here: https://developers.google.com/places/web-service/get-api-key private static readonly string API_KEY = "API_KEY_HERE"; public static string ProcessText(string text) { //build the request using the Newtonsoft.Json library StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.WriteStartObject(); //tell the google translation api to translate to english writer.WritePropertyName("target"); writer.WriteValue("en"); //add strings to translate here. to add more things to translate, just repeat the next two lines writer.WritePropertyName("q"); writer.WriteValue(text); writer.WriteEndObject(); } //build the api url and send the data string url = "https://www.googleapis.com/language/translate/v2?key=" + API_KEY; string response = ""; using(WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; response = client.UploadString(url, sb.ToString()); } //parse the response and get the first translation JObject root = JObject.Parse(response); return (string)root["data"]["translations"][0]["translatedText"]; } }