-1

I have been searching all over for a way to only translate the contents of a text box.... but I can only find ways to translate the entire website.

Below is a sample of the page code of the form we'll be submitting. I would like to just translate the contents of textarea name="emergency_procedures".

<form action="#cgi.script_name#?submit=<cfif url.id neq "">UPDATE&id=#url.id#<cfelse>YES</cfif>" method="post">
<table id="keywordEditTable" class="editTable" cellpadding="0" cellspacing="0">
    <tr>
        <td class="editLabel"><span>*</span>Type Title:</td>
        <td class="editField">
            <input type="text" name="name"<cfif url.id neq "">value="#trim(item.name)#"</cfif> size="35" />

        </td>       
    </tr>

    <tr>
        <td class="editLabel"><span>*</span>Active:</td>
        <td class="editField">
            <input type="radio" name="active"<cfif url.id eq "" or item.active eq 1> checked="checked"</cfif> value="1" />
            <label for="active">Yes</label>
            <input type="radio" name="active"<cfif url.id neq "" and item.active neq 1> checked="checked"</cfif> value="0" /> 
            <label for="active">No</label>
        </td>
    </tr>

    <tr>
        <td class="editLabel"><span>*</span>Default:</td>
        <td class="editField">
            <input type="radio" name="is_default"<cfif url.id eq "" or item.is_default eq 1> checked="checked"</cfif> value="1" />
            <label for="active">Yes</label>
            <input type="radio" name="is_default"<cfif url.id neq "" and item.is_default neq 1> checked="checked"</cfif> value="0" /> 
            <label for="active">No</label>
        </td>
    </tr>   


    <tr id="editLastRow">
        <td class="editLabel">Emergency Procedures:</td>
        <td class="editField"><textarea name="emergency_procedures" cols="67" rows="15"><cfif url.id neq "">#item.emergency_procedures#</cfif></textarea></td>
    </tr>
    <cfif url.id neq "">
    <tr id="editLastRow">
        <td class="editLabel"></td>
        <td class="editField">
       </td>
    </tr>
    </cfif>

    <tr>
        <td class="editLabel"><span>*</span>Notify URL:</td>
        <td class="editField">
            <input type="text" name="notify_url"<cfif url.id neq "">value="#item.notify_url#"</cfif> size="65" />

        </td>       
    </tr>
    <tr>

    </tr>

    <tr>
        <td></td>
        <td id="editButtons">
            <input type="submit" name="Make" value="<cfif url.id neq "">Update<cfelse>Create</cfif>" id="editButton" />
            <cfif url.id neq "">
                <input type="button" name="Delete" value="Delete" id="deleteButton" onclick="confirmDelete()" />
                <input type="hidden" name="id" value="#url.id#" />
            </cfif>
            <input type="button" name="Cancel" value="Cancel" id="cancelButton" onclick="document.location='EMB_types.cfm'" />
        </td>
    </tr>
</table>
    </cfoutput>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Scott
  • 459
  • 2
  • 10

1 Answers1

1

This is too long for a comment, but here goes. You want to use Google's REST API and / http. I haven't programmed out all the details but this should get you started

 <cfscript>
 endpoint = "https://translation.googleapis.com/language/translate/v2";

 if (cgi.request_method == "POST")  {
     httpService = new http();
     httpService.setMethod("post");
     httpService.setCharset("utf-8");
     httpService.setUrl(endpoint);
     httpService.addParam(type="formfield", name="q", value= form.emergency_procedures);
     httpService.addParam(type="formfield",name="target",value="yourlanguage");
     httpService.addParam(type="formfield",name="key",value="yourkey");

     result = httpService.send().getPrefix();
     writedump(result); 
     }
 </cfscript>

You are probably going to have tinker with the fields to get to work right. Currently the REST API documentation is at: https://cloud.google.com/translate/docs/reference/rest/v2/translate

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 1
    Yep, that's the basic approach. Though I wouldn't recommend relying on google translate for anything as important as "Emergency Procedures", even if it is allowed by the TOS. Yipes! – SOS Sep 27 '19 at 14:30
  • Sorry, that last comment was for @Scott. – SOS Sep 27 '19 at 14:53