Skip to main content
Maximum Reading Speed Check logo
Maximum Reading Speed Check BetaFree

Ensure your captions are readable by controlling the words per minute.

Get

Requires Crowdin account

var maxWPM = 160; // Define the maximum allowed WPM

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;
}

function countWords(text) {
  var words = text.trim().split(/\s+/);
  return words.length;
}

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

  var translation = crowdin.translation;
  var wordCount = countWords(translation);
  var timeInMinutes = timeDifference / 60000; // Convert milliseconds to minutes
  var wpm = wordCount / timeInMinutes;

  if (wpm > maxWPM) {
    result.message = 'The WPM (Words Per Minute) is too high: ' + wpm.toFixed(2) + ' (max allowed is ' + maxWPM + ')';
    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 30, 2024

Published by Awesome Crowdin

Identifier:maximum-reading-speed-check

All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.