Özel Kod

Custom Code is a workflow step that allows you to specify your own code snippets according to which the strings should be filtered further in the workflow. The Custom Code has one input and two outputs (true and false), so you can split strings into two workflow threads according to some specific conditions written using JavaScript.

Kullanım Durumları

You can use the custom code workflow step in the numerous scenarios. Here are a few examples:

  • To send one part of the strings to in-house translators and another part to a translation agency.
  • To send one part of the strings to machine translation and another part to crowdsourcing.
  • To send one part of the strings to in-house proofreaders and another part to proofreading by a translation agency.

Adding Custom Code Step to Your Workflow

Custom Code could be added to the workflow of your project in the workflow editor or the Workflow template editor.

Custom Code in the Workflow Editor

Kod Parçacığı Parametreleri

After you added the Custom Code step to your workflow, it’s necessary to specify the code snippet in the Custom Code field according to which the strings will be directed to either of two outputs.

Code Snippet is JavaScript-based. It Includes a crowdin object and several properties. Kod parçacığını oluşturmak amacıyla kod girişi için bu nesne şablonunu kullanın:

object crowdin {
 object file {
   string name,
   string fullName,
   string branchName,
   string type
 }
 object context {
   string context
   ?int maxLength
 },
 string contentType,
 string source
}

Find the example of a custom code snippet in Crowdin Script Editor. Kod parçacığının yapısını görmek için bağlantıyı kullanın, verilerinizle düzenleyin ve kodunuzun doğru olduğunu onaylayın.

Kod Parçacığı İsteği

Kod parçacığı isteği, aşağıda listelenen anahtarları içerir:

  1. file.name – kaynak dosya adı
  2. file.fullName – projedeki kaynak dosyanın tam yolu (varsa dal hariç)
  3. file.branchName – kaynak dosyanın saklandığı dal adı
  4. file.type – kaynak dosya türü
  5. source – kaynak metin
  6. context.maxLength – maximum length of the string
  7. context.context – context of the string that enters the input of the Custom Code step
  8. contentType – string can include one of three types:

    • text/plain
    • application/vnd.crowdin.text+plural
    • application/vnd.crowdin.text+icu

Check out the example of a code snippet request:

{
   "file": {
     "name": "strings.json",
     "fullName": "backend/strings.json",
     "branchName": "master",
     "type": "json"
   }
   "context": {
     "context": "backend.string.example.plain",
     "maxLength": 10
   },
   "contentType": 'application/vnd.crowdin.text+plural',
   "source": '{"one":"Password", "other":"Passwords"}',
}

Kod Parçacığı Yanıtı

After running the code snippet, it should return the response whether the specified conditions are met or not:

  • The response object should contain boolean success property indicating whether the specified conditions are met. Örneğin:
{
  "success": true
}
  • In case the specified conditions are not met, the string will be directed to the false output of the Custom Code step. Örneğin:
{
  "success": false
}

Bu makale yararlı oldu mu?