Tutorial 3: Translation End-to-End

This tutorial is for users who want to download translation data and show Arabic + translated text in a reliable way.

1) What This Resource Is

Translation resources provide translated Quran text keyed by ayah, with multiple export formats.

Depending on the selected package, you may get:

  • Simple translation text (JSON / SQLite)
  • Footnote-tagged translation (<sup foot_note="...">)
  • Inline-footnote translation ([[...]])
  • Text chunk format for structured rendering

Primary category:

2) When to Use It

Use translation data when you are building:

  • Multilingual Quran readers
  • Arabic + translation views for learning apps
  • Search and discovery experiences in non-Arabic languages

3) How to Get Your First Example Resource

  1. Open https://qul.tarteel.ai/resources/translation.
  2. Keep the default listing order and open the first published card.
  3. Confirm the resource detail page includes:
    • Translation Preview tab
    • Help tab
  4. Confirm available download formats shown on the page:
    • simple.json
    • simple.sqlite
    • Optional footnote/chunk variants (when provided by that translation)

This keeps onboarding concrete without hardcoding a resource ID.

4) What the Preview Shows (Website-Aligned)

On the translation detail page:

  • Translation Preview tab:
    • Jump to Ayah selector
    • Previous/next ayah navigation
    • Arabic ayah block + translated text block
  • Help tab:
    • Export format examples
    • Simple structures (nested array, key-value)
    • Footnote structures (tags, inline notes, text chunks)

Practical meaning:

  • If you only need plain text, use a simple format.
  • If you need footnotes or formatting control, use footnote-tag/chunk formats.

5) Download and Use (Step-by-Step)

  1. Download your selected translation package.
  2. Inspect what format you received:
    • Plain string by ayah key
    • Object with translation text + footnotes (t, f)
    • Chunk array with mixed text/objects
  3. Normalize to one stable key format in app code (recommended: surah:ayah).
  4. Load Quran Script data for Arabic text.
  5. Join Arabic + translation rows by the same ayah key.
  6. Render translations by format-aware rules.
  7. Validate at least 5 consecutive ayahs so you catch format edge cases.

Starter integration snippet (JavaScript):

JavaScript
// Convert source rows to one stable key like "73:4".
const ayahKeyFromRow = (row) => row.ayah_key || `${row.surah}:${row.ayah}`;

// Build lookup map for fast joins with Arabic script rows.
const buildTranslationIndex = (rows) =>
  rows.reduce((index, row) => {
    index[ayahKeyFromRow(row)] = row.translation;
    return index;
  }, {});

// Normalize the different translation payload shapes into one renderable object.
const normalizeTranslationPayload = (payload) => {
  // Simple plain-text translation.
  if (typeof payload === "string") return { text: payload, notes: [] };

  // Footnote-tag format: { t: "...<sup foot_note='x'>1</sup>...", f: { x: "note" } }
  if (payload && typeof payload === "object" && payload.t) {
    const noteIds = [];
    const text = payload.t.replace(/<sup foot_note="([^"]+)">([^<]+)<\/sup>/g, (_, id, label) => {
      noteIds.push(id);
      return `[${label}]`;
    });
    const notes = noteIds.map((id) => ({ id, text: payload.f?.[id] || "" }));
    return { text, notes };
  }

  // Text chunk format: ["plain", {type: "i", text: "italic"}, {type: "f", f: "12", text: "1"}]
  if (Array.isArray(payload)) {
    const textParts = [];
    const notes = [];
    payload.forEach((chunk) => {
      if (typeof chunk === "string") textParts.push(chunk);
      else if (chunk?.type === "i") textParts.push(chunk.text);
      else if (chunk?.type === "f") {
        textParts.push(`[${chunk.text}]`);
        notes.push({ id: chunk.f, text: `Footnote ${chunk.f}` });
      }
    });
    return { text: textParts.join(""), notes };
  }

  return { text: "", notes: [] };
};

6) Real-World Example: Arabic + Translation + Footnotes

Goal:

  • User picks an ayah and sees Arabic text plus translation, with footnotes when available.

Inputs:

  • Quran Script package (Arabic text)
  • Translation package (simple or footnote/chunk format)

Processing:

  1. User selects ayah key (example: 73:4).
  2. App loads Arabic text by ayah key.
  3. App loads translation payload by same ayah key.
  4. App normalizes payload to text + notes.
  5. UI renders translation and optional footnote list.

Expected output:

  • Arabic and translation stay correctly paired.
  • Footnotes are visible when provided.
  • Format differences do not break rendering.

Interactive preview (temporary sandbox):

You can edit this code for testing. Edits are not saved and may not persist after refresh.

JavaScript Playground
Editor
Preview

7) Common Mistakes to Avoid

  • Joining translation rows to Arabic by row order instead of ayah key.
  • Assuming every translation package has the same structure.
  • Rendering footnote-tag HTML directly without sanitization in production apps.
  • Ignoring missing footnote entries or missing ayah keys.

8) When to Request Updates or Changes

Open an issue if you find:

  • Broken download links or missing format files
  • Translation text mapped to the wrong ayah
  • Footnote IDs without matching footnote text
  • Inconsistent metadata for language/source

Issue tracker:

Related Docs