Corrupted Characters Check logo
Corrupted Characters Check Free

Detect and remove corrupted or invisible characters in your translations effortlessly.

Get

Requires Crowdin account

var result = { success: false };
var solution = [];

Array.prototype.includes = function (element) {
  return (this.indexOf(element) !== -1);
};

// A pattern for corrupted/invisible characters
var corruptedPattern = /[\uFFFD\u200B\u200C\u200D\uFEFF\u0080-\u009F\uDC00-\uDFFF]|(\u00C3[\u00A4-\u00B6])|(\u00C3\u201E)|(\u00C3\u2026)|(\u00C3\u2013)/g;

// Extract corrupted characters from the translation
var translationCorruptedChars = crowdin.translation.match(corruptedPattern) || [];
var translation_text = crowdin.translation;

if (translationCorruptedChars.length === 0) {
  result.success = true; // No corrupted characters found
} else {
  result.message = 'There are corrupted characters in the translation: ' + translationCorruptedChars.join(', ');
  
  // Suggest removing corrupted characters
  for (var i = 0; i < translationCorruptedChars.length; i++) {
    var position = translation_text.indexOf(translationCorruptedChars[i]);

    solution.push({
      from_pos: position,
      to_pos: position + 1,
      replacement: '' // Replace with an empty string to remove the corrupted character
    });
  }
}

if (result.success === false) {
  result.fixes = solution;
}

return result;
Categories
Tags
Works with
  • Crowdin Enterprise
Details

Released on Oct 6, 2024

Updated on Oct 6, 2024

Published by Community

Identifier:corrupted-characters-checker