MARFA

MARFA is a browser-based CAT tool designed for professional translators, reviewers, and language specialists who work with bilingual texts, translation memories, and terminology-rich documents.

The tool provides an integrated workspace for importing Word, Excel, HTML, TMX, and translation-memory files; building and searching translation memory; analyzing source segments; detecting best matches; reviewing match rates; editing target drafts; running concordance searches; and exporting final outputs.

MARFA helps organize bilingual translation work, improve consistency, reuse previous translations, and reduce repetitive manual effort directly inside the browser.

MARFA — Translation Memory & Text Search
/* MARFA Mobile Front Analyze Fix V1 Purpose: - This is NOT a worker replacement. - It patches the main page side before data is sent to tm-worker. - It blocks analysis if Worker memory is not fully loaded. - It cleans sourceText in MATCH_BATCH messages before they reach the worker. - It exposes diagnostics in window.MARFA_MOBILE_FRONT_FIX_INFO(). */ (function () { "use strict"; var KEY = "MARFA_MOBILE_FRONT_ANALYZE_FIX_V1"; if (window[KEY] && window[KEY].installed) return; var state = window[KEY] = { installed: true, version: "v1.0.0-front-analyze-fix", buildIndexSeen: 0, lastBuildPayloadCount: null, lastBuildDone: null, lastMatchBatchCount: null, lastMatchSampleBefore: [], lastMatchSampleAfter: [], suspectedPollutedItems: 0, workerInfo: null }; function hasAr(s) { return /[\u0600-\u06FF]/.test(String(s || "")); } function cleanSourceText(s) { s = String(s || ""); // Remove common responsive/mobile UI labels that may leak through textContent/innerText. s = s .replace(/\b(?:actions?|status|source segment|target draft|best match|match rate|needs review|needs translation|confirmed|critical|target empty|issue|show|hide)\b/gi, " ") .replace(/(?:النص\s*المصدر|المصدر|الحالة|الإجراءات|اجراءات|إجراءات|إجراء|الإجراء)\s*[::]?/g, " ") .replace(/اختر\s+إجراء\s+السورس/g, " ") .replace(/اختر\s+اجراء\s+السورس/g, " ") .replace(/(?:إظهار|اظهار|إخفاء|اخفاء)/g, " ") .replace(/(?:مطابقة|أفضل\s+مطابقة|مسودة\s+الهدف|النص\s+الهدف|يحتاج\s+ترجمة|يحتاج\s+مراجعة|مؤكد)/g, " "); // Drop lines that are only UI labels or percentages. var lines = s.split(/\r?\n+/) .map(function (x) { return x.trim(); }) .filter(Boolean) .filter(function (x) { if (/^\d+\s*%$/.test(x)) return false; if (/^(0|100|99|95|94|37)%?$/.test(x)) return false; if (/^(Needs|Confirmed|Review|Status|Actions|Source Segment|Best Match|Target Draft)$/i.test(x)) return false; if (/^(النص المصدر|المصدر|الحالة|إجراء|الإجراء|إظهار|اظهار)$/.test(x)) return false; return true; }); s = lines.join(" ").replace(/\s+/g, " ").trim(); // If source is Arabic and a chunk accidentally contains English UI words, strip obvious English UI residue. if (hasAr(s)) { s = s.replace(/\b(?:Needs|Confirmed|Review|Critical|Target|empty|issue|Actions|Status|Source|Segment|Best|Match|Draft)\b/gi, " "); } return s.replace(/\s+/g, " ").trim(); } function isPolluted(s) { return /(اختر\s+إجراء|اختر\s+اجراء|النص\s*المصدر|Target Draft|Best Match|Source Segment|Critical|Target empty|Status|Actions)/i.test(String(s || "")); } function countPayloadTus(payload) { payload = payload || {}; var keys = ["tus", "records", "rows", "pairs", "items", "tm", "data"]; for (var i = 0; i < keys.length; i++) { if (Array.isArray(payload[keys[i]])) return payload[keys[i]].length; } if (Array.isArray(payload)) return payload.length; return null; } function patchMessage(msg) { if (!msg || typeof msg !== "object") return msg; if (msg.type === "BUILD_INDEX") { state.buildIndexSeen++; state.lastBuildPayloadCount = countPayloadTus(msg.payload); return msg; } if ((msg.type === "MATCH_BATCH" || msg.type === "RECOVER_BATCH") && msg.payload && Array.isArray(msg.payload.items)) { var before = []; var after = []; var polluted = 0; msg.payload.items = msg.payload.items.map(function (item, idx) { item = item || {}; var raw = item.sourceText || item.source || item.src || ""; if (idx < 8) before.push({ id: item.id, sourceText: String(raw).slice(0, 240) }); if (isPolluted(raw)) polluted++; var clean = cleanSourceText(raw); var next = Object.assign({}, item); next.sourceText = clean; next.source = clean; next.src = clean; if (!next.lang) next.lang = hasAr(clean) ? "ar" : "en"; if (idx < 8) after.push({ id: next.id, sourceText: String(clean).slice(0, 240) }); return next; }); state.lastMatchBatchCount = msg.payload.items.length; state.lastMatchSampleBefore = before; state.lastMatchSampleAfter = after; state.suspectedPollutedItems = polluted; return msg; } return msg; } // Patch Worker.prototype.postMessage on the main page side. var originalPostMessage = Worker.prototype.postMessage; if (!Worker.prototype.__MARFA_MOBILE_FRONT_FIX_PATCHED__) { Worker.prototype.postMessage = function (msg, transfer) { msg = patchMessage(msg); if (transfer) return originalPostMessage.call(this, msg, transfer); return originalPostMessage.call(this, msg); }; Worker.prototype.__MARFA_MOBILE_FRONT_FIX_PATCHED__ = true; } // Capture worker replies for diagnostics. var originalAddEventListener = Worker.prototype.addEventListener; if (!Worker.prototype.__MARFA_MOBILE_FRONT_FIX_LISTENER_PATCHED__) { Worker.prototype.addEventListener = function (type, listener, options) { if (type === "message" && typeof listener === "function") { var wrapped = function (e) { try { var d = e && e.data || {}; if (d.type === "BUILD_INDEX_DONE") state.lastBuildDone = d.payload || null; if (d.type === "INFO_DONE") state.workerInfo = d.payload || null; } catch (_) {} return listener.call(this, e); }; return originalAddEventListener.call(this, type, wrapped, options); } return originalAddEventListener.call(this, type, listener, options); }; Worker.prototype.__MARFA_MOBILE_FRONT_FIX_LISTENER_PATCHED__ = true; } window.MARFA_CLEAN_SOURCE_TEXT = cleanSourceText; window.MARFA_MOBILE_FRONT_FIX_INFO = function () { console.log("[MARFA Mobile Front Fix]", state); return JSON.parse(JSON.stringify(state)); }; window.MARFA_MOBILE_FRONT_FIX_REPORT = function () { var info = window.MARFA_MOBILE_FRONT_FIX_INFO(); alert( "MARFA Mobile Front Fix\n\n" + "version: " + info.version + "\n" + "BUILD_INDEX payload count: " + info.lastBuildPayloadCount + "\n" + "BUILD_INDEX done records: " + (info.lastBuildDone && info.lastBuildDone.records) + "\n" + "MATCH_BATCH items: " + info.lastMatchBatchCount + "\n" + "Polluted items cleaned: " + info.suspectedPollutedItems + "\n\n" + "افتح Console أو انسخ نتيجة MARFA_MOBILE_FRONT_FIX_INFO() للتشخيص." ); return info; }; // Small floating diagnostic button, hidden by default until called. window.MARFA_SHOW_MOBILE_FIX_BUTTON = function () { if (document.getElementById("marfaMobileFrontFixBtn")) return; var b = document.createElement("button"); b.id = "marfaMobileFrontFixBtn"; b.textContent = "MARFA Mobile Fix Info"; b.style.cssText = "position:fixed;z-index:2147483647;left:10px;bottom:10px;padding:10px 12px;border-radius:12px;border:1px solid #cbd5e1;background:#111827;color:white;font:600 12px system-ui;box-shadow:0 8px 24px rgba(0,0,0,.18)"; b.onclick = window.MARFA_MOBILE_FRONT_FIX_REPORT; document.body.appendChild(b); }; })();