​x
40
 
1
var result = {success: false};
2
​
3
source = crowdin.source.replace(/(?:\r\n|\r)/g, '\n');
4
translation = crowdin.translation.replace(/(?:\r\n|\r)/g, '\n');
5
sourceMatch = source.match(/^[ ]+/g);
6
translationMatch = translation.match(/^[ ]+/g);
7
​
8
if (null != sourceMatch) {
9
    sourceMatch = sourceMatch[0];
10
}
11
​
12
if (null != translationMatch) {
13
    translationMatch = translationMatch[0];
14
}
15
​
16
sourceLeadingSpaces = null !== sourceMatch ? sourceMatch.length : 0;
17
translationLeadingSpaces = null !== translationMatch ? translationMatch.length : 0;
18
​
19
if (sourceLeadingSpaces != translationLeadingSpaces) {
20
    if (sourceLeadingSpaces == 0) {
21
        result.message = 'The source text does not begin with a space, please remove ' + translationLeadingSpaces + ' space(s) at the beginning of your translation.';
22
    } else if (translationLeadingSpaces == 0) {
23
        result.message = 'The source text begins with ' + sourceLeadingSpaces + ' space(s), please add ' + sourceLeadingSpaces + ' space(s) at the beginning of your translation.';
24
    } else {
25
        result.message = 'The source text begins with ' + sourceLeadingSpaces + ' space(s), please use the same amount of spaces at the beginning of your translation.';
26
    }
27
    if (sourceLeadingSpaces > translationLeadingSpaces) {
28
        result.fixes = [{
29
            from_pos: 0,
30
            to_pos: 0,
31
            replacement: sourceMatch.slice(0, sourceLeadingSpaces - translationLeadingSpaces)
32
        }];
33
    } else {
34
        result.fixes = [{from_pos: 0, to_pos: translationLeadingSpaces - sourceLeadingSpaces, replacement: ''}];
35
    }
36
} else {
37
    result.success = true;
38
}
39
​
40
return result;
Request
 
{
  "sourceLanguage": "en",
  "targetLanguage": "uk",
  "context": {
    "maxLength": 10
  },
  "contentType": "text/plain",
  "source": "Strings",
  "translation": "Рядки"
}
Response
 
​