Characters Per Second Check logo
Characters Per Second Check BetaFree

Ensure your captions are readable by controlling the character count per second.

Get

Requires Crowdin account

  var maxCPS = 15; // Define the maximum allowed CPS (Characters Per Second)

var result = {
  success: false
};

function getTimeDifference(timeString) {
  var timePattern = /(\d{2}):(\d{2}):(\d{2}),(\d{3})/g;
  var matches = timeString.match(timePattern);

  if (matches.length !== 2) {
    result.message = "Invalid time string format";
    return result;
  }

  function parseTime(time) {
    var parts = time.match(/(\d{2}):(\d{2}):(\d{2}),(\d{3})/).slice(1);
    return (
      parseInt(parts[0]) * 3600000 +
      parseInt(parts[1]) * 60000 +
      parseInt(parts[2]) * 1000 +
      parseInt(parts[3])
    );
  }

  var startTime = parseTime(matches[0]);
  var endTime = parseTime(matches[1]);

  return endTime - startTime;
}

if (crowdin.contentType === 'text/plain' && crowdin.context.context) {
  var timeDifference = getTimeDifference(crowdin.context.context);
  
  if (timeDifference === null) {
    return result;
  }

  var translation = crowdin.translation;
  var translationLength = translation.length;
  var cps = translationLength / (timeDifference / 1000);

  if (cps > maxCPS) {
    result.message = 'The CPS (Characters Per Second) is too high: ' + cps.toFixed(2) + ' (max allowed is ' + maxCPS + ')';
    result.fixes = [];
  } else {
    result.success = true;
  }
} else {
  result.message = 'Invalid content type or missing context';
  result.fixes = [];
}

return result;
Categories
Works with
  • Crowdin Enterprise
Details

Released on Jul 26, 2024

Updated on Jul 14, 2025

Published by Awesome Crowdin

Identifier:characters-per-second-check

Characters Per Second (CPS) Check for Captions