Address Autocomplete in Tunisia: Arabic & Arabizi10 min read1,969 words

Address Autocomplete in Tunisia: Arabic & Arabizi

Build Tunisian address autocomplete for French, Arabic and Arabizi. Learn RTL display, query normalization, request handling and confidence checks.

address autocomplete TunisiaArabic address autocompleteArabizi address searchgeocoding APIright-to-left interface
Address Autocomplete in Tunisia: Arabic & Arabizi

Build Address Autocomplete That Understands Tunisia's Three Writing Systems

An address field in Tunisia has to handle more than spelling variations. The same place might be typed in French, Arabic, or Arabizi: Tunisian Arabic written with Latin characters, often with numbers to represent sounds that don't map neatly to French letters. Someone might enter "Rue de Marseille," "نهج مرسيليا," or "nahj marseille." They might also search for "9asr said" instead of Ksar Said.

If your checkout only understands one version, the break shows up at the worst time in the user journey: right when someone is trying to place an order. Even a technically correct search box can fail when it can't match how people actually type, displays Arabic with the wrong text direction, or returns a result that's too ambiguous to choose confidently.

This guide walks through a practical autocomplete flow built around a geocoding API. We'll cover request timing, Arabic right-to-left rendering, browser-side Arabizi normalization, running searches in parallel, improving result quality, and how to decide when a suggestion is safe enough to prefill a delivery address.

Why Tunisian address search needs more than one spelling

Address search is often treated as a simple geocoding problem: send a text string to an API and use the coordinates it returns. But in production, the harder part is deciding what text to send in the first place. People don't always follow the spelling conventions stored in a map database, and they don't all use the same writing system.

In Tunisia, someone may write an address in French, in Arabic, or in Arabizi. Arabizi uses Latin letters and numbers to represent Arabic sounds. For example, 3 for ع, 5 for خ, 7 for ح, and 9 for ق. So "9asr said" is a common way to write Ksar Said, while "7ammamet" usually points to Hammamet.

Road-type words vary, too. A person might type nahj for a street, zan9a or zan9et for a lane or alley, chare3 for an avenue, and 7ay for a neighbourhood or district. These aren't "mistakes." They're just normal input choices your search experience has to handle.

What a missed match costs

For a map browsing tool, a weak match might just be annoying. For a checkout or delivery form, it can mean a customer abandons the order, enters an incomplete address, or picks a similarly named place in the wrong area. The impact depends on the product, but the core issue stays the same: search quality shapes how reliable the address data you collect actually is.

A good design goal isn't "understand every possible spelling." That's open-ended, and it's usually not realistic. Instead, focus on the common input patterns, show enough geographic context that a person can judge the result, and make it easy to correct an uncertain location on a map.

A small Arabizi reference

Arabizi character Arabic character Example Common Latin spelling
3 ع 3in Ain
5 خ 5ayreddine Khayreddine
7 ح 7ammamet Hammamet
9 ق 9asr said Ksar Said

This mapping is a helpful starting point, not a universal transliteration standard. People use different spellings, and even the "same" digit can behave differently depending on the word. That's why normalizing input should broaden what you can find - without pretending there's only one correct way to type.

How to build a reliable autocomplete request

A basic autocomplete sends a forward-geocoding request while the person types. The UI feels responsive only if you control request volume and stop old results from overwriting newer ones. In practice, three details do most of the work: a short debounce, request cancellation, and geographic proximity.

let timer;

let controller;

input.addEventListener('input', () => {

clearTimeout(timer);

timer = setTimeout(search, 300);

});

async function geocode(q, signal) {

const url = new URL('https://api.tmaps.tn/geocoding/forward');

url.search = new URLSearchParams({

q,

country: 'TN',

limit: 5,

lang: languageSelect.value,

proximity: '36.8065,10.1815',

api_key: API_KEY,

});

const response = await fetch(url, { signal });

const data = await response.json().catch(() => ({}));

if (!response.ok) {

throw new Error(`${response.status}: ${data.error ?? response.statusText}`);

}

return data.results;

}

Debounce to avoid one request per keystroke

The 300-millisecond delay gives people a moment to finish a word before you call the API. Without it, typing a 12-character address can trigger a burst of requests - many of which won't matter by the time they arrive. A delay in the 250-350 millisecond range is a sensible starting point. Then tune it based on real typing behavior, perceived latency, and your provider's usage limits.

Longer delays cut traffic but can feel sluggish. Shorter delays feel snappier but increase request volume. There isn't one magic number - measure and adjust.

Cancel stale requests

Debouncing doesn't stop an older request from returning after a newer one. If "Tunis" comes back slowly, it could overwrite suggestions for "Tunis centre." The fix is to cancel the previous fetch when a new search starts:

async function search() {

const query = input.value.trim();

if (query.length < 3) return;

controller?.abort();

controller = new AbortController();

try {

const results = await geocode(query, controller.signal);

render(results);

} catch (error) {

if (error.name !== 'AbortError') {

showSearchError(error);

}

}

}

And don't treat cancellations like errors. An intentional AbortError should stay quiet. Also, if the input becomes too short, clear or update the suggestion list - otherwise outdated suggestions can linger on screen after the user changes the query.

Use proximity and country restrictions

Set country to Tunisia when the field is meant for Tunisian addresses. Proximity helps rank places near the customer (or the current map view). This matters because street names repeat across towns.

A fixed point in Tunis can work for demos, but production code should use the user's location when available, or fall back to the map center.

Proximity is a hint, not a guarantee. For common street names, you still need to show the locality and administrative area in each suggestion so the person can tell the difference between similarly named places.

How to display Arabic and normalize Arabizi

Search and display are two separate problems. An API can return the right Arabic address, but the UI can still make it hard to read if everything is forced into left-to-right direction. Mixed-language suggestions often include Arabic, Latin text, and Western numerals in the same list - so locking the whole component to a single direction tends to break things.

Let each text field determine its direction

Use dir="auto" on the input and on each suggestion. The browser picks direction based on the first strong directional character it sees. Arabic flows right-to-left; Latin stays left-to-right.

const item = document.createElement('li');

item.dir = 'auto';

item.textContent = result.formatted;

const addressInput = document.querySelector('#address');

addressInput.dir = 'auto';

This also makes cursor movement and punctuation behave more naturally when someone switches scripts. Avoid forcing everything to right-to-left just because the UI language is Arabic - some results may still include a Latin road number or an administrative name in a different script.

When the API provides Arabic results, an address might look like this:

{

"formatted": "نهج مرسيليا, حبيب ثامر, باب بحر, تونس, تونس",

"type": "street",

"confidence": 0.8

}

Render the API response as text, not HTML. Treat address content as content, not markup.

Normalize common dialect terms without destroying useful input

Some Arabizi queries work as-is; others match better when you also try a second query using the spelling conventions from your address database. A small, explicit mapping can handle common road terms and Arabizi characters:

const DIALECT = {

nahj: 'rue',

nhej: 'rue',

zan9a: 'impasse',

zan9et: 'impasse',

zanket: 'impasse',

chare3: 'avenue',

chara3: 'avenue',

hay: 'cité',

'7ay': 'cité',

};

const ARABIZI = { 3: 'a', 5: 'kh', 7: 'h', 9: 'k' };

function normalizeTunisian(text) {

return text.toLowerCase().split(/\s+/).map((word) => {

if (DIALECT[word]) return DIALECT[word];

// Preserve standalone numbers and road codes such as RN9 or C27.

if (!/[a-z]/.test(word) || /^[a-z]{1,2}\d+$/.test(word)) {

return word;

}

return word

.replace(/3a/g, 'a')

.replace(/[3579]/g, (digit) => ARABIZI[digit]);

}).join(' ');

}

The protections are important. A Tunisian address might include a street number like "Rue 4014" or a road code like "RN9" or "C27." If you blindly rewrite every digit, you can turn a valid query into something the geocoder won't recognize.

This mapping is intentionally narrow. Add terms based on real queries from your users, and test them against real local addresses. Overdoing normalization can reduce search quality by rewriting queries the geocoder already understands.

How to merge results and handle uncertain matches

If normalization changes a query, don't throw the original away - search both. The original might already match (for example, "9asr said" can match Ksar Said without any rewrite). Keeping both paths gives you more coverage and avoids accidentally losing a good result.

async function search() {

const query = input.value.trim();

if (query.length < 3) return;

controller?.abort();

controller = new AbortController();

const normalized = normalizeTunisian(query);

const queries = normalized === query.toLowerCase()

? [query]

: [query, normalized];

try {

const lists = await Promise.all(

queries.map((text) => geocode(text, controller.signal))

);

const seen = new Set();

const results = lists.reverse()

.flat()

.filter((result) => {

if (seen.has(result.formatted)) return false;

seen.add(result.formatted);

return true;

})

.slice(0, 5);

render(results);

} catch (error) {

if (error.name !== 'AbortError') showSearchError(error);

}

}

In this version, normalized-query results are considered first, then the original-query results, and duplicates are removed using the formatted address. You can flip that priority if testing shows raw input is more reliable for your users. The key is to make it a product decision: test against a representative set of searches instead of assuming normalization should always "win."

Running a normalized query usually means two API requests instead of one. That adds a bit of latency, but it keeps coverage high. If usage limits become a concern, narrow the normalization rules or cache repeated queries.

Check confidence before saving coordinates

A geocoder's top suggestion isn't automatically a verified delivery point. Results often include a formatted address, coordinates in geometry.location, a confidence score, and components like locality, delegation, and governorate. Use those fields to help the user decide, not just to auto-fill hidden form values.

A practical approach for delivery flows could look like this:

  • At confidence of 0.85 or higher, treat the result as a strong candidate, but still show it to the user.
  • Below that threshold, keep it as a suggestion and ask the user to confirm the location on a map.
  • If multiple places share a name, include locality and governorate in the suggestion label so the user can tell which one you mean.

The 0.85 number is just an example. Calibrate it using your own delivery failures and support tickets. Confidence is a signal, not proof that a driver can reach the right building.

A reliable checkout should let the customer select a result, check the locality and administrative components, and adjust the pin if needed. Then you can use reverse geocoding after confirmation to refine the address based on where the user placed the marker. That's your feedback loop: the API helps narrow options, and the customer verifies the part that matters operationally.

Test the gaps, not just the working demo

Build a test set that includes searches that already work and searches that require normalization. For example: Arabic "نهج مرسيليا," "nahj marseille," "9asr said," "7ammamet," and "5ayreddine" cover common paths. "3in zaghouan" can show whether Arabizi normalization helps find Ain Zaghouane. "zan9et el bacha" can reveal cases where the text match might return the wrong road type.

Record what you get the first time, what alternatives you show, and whether the user ends up with the correct pin. If two similarly named locations compete, test with different proximity values. Good performance isn't just whether the API returns something - it's whether people can reliably pick the right place.

Conclusion

A good Tunisian address autocomplete is more than "a text field plus a geocoder." Debouncing and request cancellation keep typing smooth. Country and proximity settings improve relevance. dir="auto" makes mixed Arabic and Latin display readable, and cautious Arabizi normalization can broaden search coverage without rewriting every input.

The biggest production decision is how much trust to put into a returned match. Show enough context for users to spot the wrong town, and give them a clear way to confirm the pin when the geocoder is unsure. Start with common local queries, measure where people still miss, and expand normalization only when real usage proves it helps.

Frequently Asked Questions

Arabizi is Tunisian Arabic written with Latin letters and, often, numbers for Arabic sounds. For example, 9 can represent ق, so “9asr said” may refer to Ksar Said. People also use dialect terms such as nahj and zan9a for types of roads.
Set dir="auto" on the search input and on each suggestion. This lets the browser determine direction from the text itself, so Arabic displays right to left while Latin text remains left to right. It also avoids forcing one direction onto mixed-script addresses.
Usually not. Search the raw query and, when normalization changes it, search the normalized query as well. The original spelling may already match the geocoder, and replacing it could remove a useful result. Merge the responses and remove duplicates before displaying suggestions.
No. Confidence helps rank or qualify a match, but it does not guarantee that the pin is on the right building or that the location is serviceable. Use the score alongside locality details and, for uncertain matches, let the customer verify or adjust the pin on a map.

Related articles