Same count of numbers logo
Same count of numbers Free

Different count of the numbers in the translation and in the source text

Get

Requires Crowdin account

var phoneNumberPattern = new RegExp('(?<=\\s|^)([+]{1,1}[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\.0-9]+)(?=\\s|$)', 'gm');

var result = {
  success: false
};

if (crowdin.contentType === 'application/vnd.crowdin.text+plural') {
  var obj = JSON.parse(crowdin.source);

  if (obj[crowdin.context.pluralForm] != null) {
    source = obj[crowdin.context.pluralForm]
  } else {
    source = obj.other
  }
} else {
  source = crowdin.source
}

translation = crowdin.translation;

var sourceMatchArray = [];

while (matchIterator = phoneNumberPattern.exec(source)) {
  sourceMatchArray.push(matchIterator[1])
}

var translationMatchArray = [];

while (matchIterator = phoneNumberPattern.exec(translation)) {
  translationMatchArray.push(matchIterator[1])
}

sourceInsertedWordCount = sourceMatchArray !== null ? sourceMatchArray.length : 0;
translationInsertedWordCount = translationMatchArray !== null ? translationMatchArray.length : 0;

if (sourceInsertedWordCount !== translationInsertedWordCount) {
  result.message = 'There are different count of phone numbers in the source text and translation: ' + sourceInsertedWordCount + ' in source, ' + translationInsertedWordCount + ' in translation.';
  result.fixes = [];
} else {
  result.success = true;
}

return result;
Categories
Tags
Works with
  • Crowdin Enterprise
Details

Released on Jan 18, 2021

Updated on Jul 12, 2024

Published by Crowdin

Identifier:same-count-of-numbers-custom