Как перевести только содержимое текстового поля? - PullRequest
0 голосов
/ 27 сентября 2019

Я искал способ перевести только содержимое текстового поля .... но я могу найти только способы перевести весь сайт.

Ниже приведен пример кода страницы формы, которую мы будем отправлять.Я хотел бы просто перевести содержимое 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>

1 Ответ

1 голос
/ 27 сентября 2019

Это слишком долго для комментария, но здесь идет.Вы хотите использовать Google REST API и / http.Я не запрограммировал все детали, но это должно помочь вам начать

 <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>

Возможно, вам придется повозиться с полями, чтобы начать работать правильно.В настоящее время документация REST API находится по адресу: https://cloud.google.com/translate/docs/reference/rest/v2/translate

...