Duplicate punctuation symbols logo
Duplicate punctuation symbols Free

Checks whether the translation contains duplicated punctuation symbols

Get

Requires Crowdin account

/**
 * Config section
 * Define the punctuation symbols below
 */

var arrayOfPunctuation = [',','.',':',';','!','?'];

/**
 * Code section
 */

var duplicatedPunctuationsPattern = new RegExp('(?<!\\.)(?!\\.{3}(?!\\.))(['+arrayOfPunctuation.join('')+'])\\1+', 'gmu');

var result = {
  success: false
};

translation = crowdin.translation;

var translationMatchArray = translation.match(duplicatedPunctuationsPattern);

if (translationMatchArray != null) {
  result.message = 'There are duplicated punctuation symbols in the translation.';
  result.fixes = [];

  while ((matchInfo = duplicatedPunctuationsPattern.exec(translation))) {
    var fix;

    if(matchInfo[0].indexOf('.') !== -1 && matchInfo[0].length > 3) {
      fix = {
        from_pos: matchInfo.index,
        to_pos: matchInfo.index + matchInfo[0].length,
        replacement: '...'
      };
    } else {
      fix = {
        from_pos: matchInfo.index,
        to_pos: matchInfo.index + matchInfo[0].length,
        replacement: matchInfo[0][0]
      };
    }

    result.fixes.splice(0, 0, fix)
  }
} else {
  result.success = true;
}

return result;
Categories
Tags
Works with
  • Crowdin Enterprise
Resources
Details

Released on Jan 18, 2021

Updated on Jul 12, 2024

Published by Crowdin

Identifier:duplicate-punctuation-symbols-custom

Duplicate punctuation symbols | Localization Quality Assurance