【问题标题】:How to translate just contents of a textbox?如何只翻译文本框的内容?
【发布时间】:2023-03-13 06:40:01
【问题描述】:

我一直在寻找一种只翻译文本框内容的方法……但我只能找到翻译整个网站的方法。

下面是我们将要提交的表单的页面代码示例。我只想翻译 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>

【问题讨论】:

  • 从什么翻译成什么?怎么样?

标签: coldfusion google-translate cfml


【解决方案1】:

这对评论来说太长了,但这里是。你想使用 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

【讨论】:

  • 是的,这就是基本方法。尽管我不建议在像“紧急程序”这样重要的事情上依赖谷歌翻译,即使 TOS 允许。耶!
  • 抱歉,最后一条评论是给@Scott的。
猜你喜欢
  • 1970-01-01
  • 2022-11-07
  • 1970-01-01
  • 1970-01-01
  • 2015-10-08
  • 2013-09-05
  • 1970-01-01
  • 1970-01-01
  • 2014-04-15
相关资源
最近更新 更多