AddTu

From Wordfast Wiki
Jump to: navigation, search

Return to command list

addTu

addTu (string key, int cmd, string source, string target, boolean forceAttributes, String tuDate, String userId, String attribute1, String attribute2, String attribute3, String attribute4, boolean doNotAddDuplicate)

Add a Translation Unit to the available Translation Memories in write mode. The number of TMs in write mode in currently limited to one.

Parameters

key string a valid API Key, generated by making a share at www.freetm.com
cmd int command number is 10
source string source segment
target string target segment
forceAttributes boolean The value of the remaining fields of a TU: the date, userID and attributes are set automatically. If you want to set your own values, forceAttributes should be set to true. Default value is false.
tuDate string optional - The date of creation of the TU. The default value is the date and time of the add. If you want to keep the date of an existing TU, you should set first forceAttribute parameter to true and respect the format: yyyyMMdd~hhmmss
userId string optional - The ID of the creator of the TU. The default value is an automatic ID generated by Wordfast Anywhere. If you want to set your own ID or keep the ID of an existing TU, you should set first forceAttributes parameter to true.
attribute1 string optional - The first attribute. The default value is the value set on Wordfast Anywhere for the selected TM. If you want to set your own value or keep the value of an existing TU, you should set first forceAttributes parameter to true. If forceAttributes parameter is set to true, the default value is an empty string.
attribute2 string optional - The second attribute. The default value is the value set on Wordfast Anywhere for the selected TM. If you want to set your own value or keep the value of an existing TU, you should set first forceAttributes parameter to true. If forceAttributes parameter is set to true, the default value is an empty string.
attribute3 string optional - The third attribute. The default value is the value set on Wordfast Anywhere for the selected TM. If you want to set your own value or keep the value of an existing TU, you should set first forceAttributes parameter to true. If forceAttributes parameter is set to true, the default value is an empty string.
attribute4 string optional - The forth attribute. The default value is the value set on Wordfast Anywhere for the selected TM. If you want to set your own value or keep the value of an existing TU, you should set first forceAttributes parameter to true. If forceAttributes parameter is set to true, the default value is an empty string.
doNotAddDuplicate boolean optional - If doNotAddDuplicate parameter is set to true, when you want to add a TU that is already existing in the TM, nothing is done. The default value is false because the TM server is asked to make a control of duplicate. if doNotAddDuplicate is set to true, a lower priority is applied to the command.

Returned value

tms array Add result detail for each TM
tmid int TM ID
success boolean result of the command (true or false)
error string error message

Request example

json post with javascript

var data = {};
data["key"] = "example@key";
data["cmd"] = 10;
data["source"] = "The brown fox is jumping over the lazy dog.";
data["target"] = "Le renard brun saute par dessus le chien paresseux.";
data["forceAttributes"] = false;
data["doNotAddDuplicate"] = false;
var xhr = new XMLHttpRequest();
xhr.open("POST", "www.freetm.com/wfa/api", true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify(data));

post

<form action="www.freetm./wfa/api" method="post">
 Key: <input type="text" id="key" name="key" value="example@key"/>
 Command: <input type="text" id="cmd" name="cmd" value="10"/>
 Source: <textarea id="source" name="source" style="width: 500px; height: 60px;"></textarea>
 Target: <textarea id="target" name="target" style="width: 500px; height: 60px;"></textarea>
 forceAttributes: <input type="text" id="forceAttributes" name="forceAttributes" value="0"/>
 doNotAddDuplicate: <input type="text" id="doNotAddDuplicate" name="doNotAddDuplicate" value="0"/>
 <input type="submit" value="Submit">
</form>

get

www.freetm.com/wfa/api?key=example@key&cmd=10&source=xxx&target=yyy&forceAttributes=0&doNotAddDuplicate=0

Response example

json

{

  "tms": [{
              "tmid":1
              ,"success": true
              ,"error": ""
          }
          ,{
              "tmid":2
              ,"success": false
              ,"error": "TM must be reorganized"
          }
          ,{...}
         ]                   
}

without white space (new line, carriage return or tabulation).

text

1 : trueLF
2 : TM must be reorganizedLF

LF is a Line feed (new line \u000A)

Remarks

When the command is used with the "do not duplicate" option or within a batch, the priority is automatically decreased.