BroadRouter

Design an AI experience for multiple languages

By the BroadNet Inference team · 7 min read · Published

Store two settings: the interface locale and the content language, and never infer one from the other. Set direction from the locale, isolate user and model text with dir="auto" or bdi, format numbers and dates with the locale, normalise digits on input, treat language detection as a hint, and evaluate quality and cost per language.

An AI feature for Arabic, English and Spanish users is three products sharing one codebase. The screen must flip direction for Arabic. Messages mix scripts in a single line. Numbers and dates change shape by region. The model may answer in the wrong language, and each language costs a different amount. Most of these problems come from one design mistake: treating “the language” as a single setting.

This post covers the product and interface side. Translating your app’s own strings (placeholders, plurals, ICU messages) is in translating app strings to Arabic with an LLM; prompt wording is in Arabic prompt engineering.

Why keep the interface locale separate from the model language?

Because they answer different questions. The interface locale (ar-SA, en-US, es-MX) decides layout direction, the language of your buttons, and how numbers and dates look. The content language is the language of a particular message, document or recording, and decides what you ask the model to do.

They diverge all the time. A Saudi user with an Arabic interface pastes an English contract. A Spanish user uploads an Arabic invoice photo. A bilingual agent switches language mid-conversation (code-switching). If the code sends “answer in Arabic” because the interface is Arabic, the English contract gets an Arabic summary nobody asked for.

So store both per user, and per message:

  • ui_locale: chosen by the user, defaulting to the browser’s language.
  • answer_language: an explicit user choice if they made one, otherwise the detected language of the message.
  • For audio, audio_language: what you pass to the transcription model. BroadNet’s API reference says to always send language with a transcription request, or Arabic can come back in Latin letters.

How do you support right-to-left and mixed-direction text?

Three layers, from the W3C’s guidance:

  1. Page direction from the locale. Set dir="rtl" and lang="ar" on the html element for Arabic. The W3C says not to use CSS to set the base direction, and to use logical values (start and end) for margins, padding and alignment rather than left and right.
  2. Logical CSS. margin-inline-start instead of margin-left, text-align: start instead of left. MDN describes logical properties as controlling layout “through logical rather than physical direction”. One stylesheet then serves both directions.
  3. Isolate text you didn’t write. User messages, model answers, product names and order codes have their own direction. The W3C’s rule: if you don’t know the direction of text inserted at run time, add dir="auto" to the element that wraps it, or wrap it in a bdi element. Without isolation, an English order code at the end of an Arabic sentence can jump to the wrong side, and punctuation lands in odd places.

For a chat interface that means dir="auto" on every message bubble, since each message picks its direction from its first strong character, and bdi around names and codes inside your own interface strings. Where there is no markup (push notifications, SMS, CSV exports), the Unicode Bidirectional Algorithm’s isolates do the same job: U+2068 FIRST STRONG ISOLATE before the text and U+2069 POP DIRECTIONAL ISOLATE after it.

Model output adds one more case: Markdown. A model answering in Arabic may include English code, URLs or table cells. Render code blocks with dir="ltr" explicitly, and give each paragraph and table cell dir="auto".

How should numbers and dates differ by locale?

Let the platform format them, and test what it actually produces. We ran Intl.NumberFormat and Intl.DateTimeFormat in Node 24.22.1 (ICU 78.3, CLDR 48) for 1234.5 and 15 November 2026:

Locale Number Date (long) Direction
en-US 1,234.5 November 15, 2026 ltr
ar-SA ١٬٢٣٤٫٥ ١٥ نوفمبر ٢٠٢٦ rtl
ar-SA-u-nu-latn 1,234.5 15 نوفمبر 2026 rtl
ar-AE 1,234.5 15 نوفمبر 2026 rtl
es-ES 1234,5 15 de noviembre de 2026 ltr
es-MX 1,234.5 15 de noviembre de 2026 ltr

Four things to notice. Arabic locales differ on digits: Saudi defaults to Arabic-Indic, the UAE to Western, and the -u-nu-latn extension (see MDN’s numberingSystem) switches a locale to Western digits. Spanish differs by region: Spain uses a comma decimal and, for a four-digit number, no thousands separator; Mexico uses a dot. Month names vary across the Arab world too: ar-MA printed نونبر for November where ar-SA printed نوفمبر. And browsers ship their own ICU versions, so run the same checks in your target browsers.

Plurals follow CLDR rules: Intl.PluralRules for ar returned six categories for 0, 1, 2, 3, 11 and 100 (zero, one, two, few, many, other), while English and Spanish returned only one and other for those numbers. The strings side of this is in the app strings post.

On input, accept both digit forms. A user may type ١٢٣٤ into a quantity field; normalise to ASCII digits before parsing, and before sending numbers to a model if your prompts compare them.

Can you detect the language of each message?

Partly. Telling Arabic script from Latin script is easy and reliable: count characters in the Arabic Unicode block. Telling English from Spanish, or reading very short messages, needs a trained model. fastText publishes two language-identification models for 176 languages (lid.176.bin, 126 MB, and the compressed lid.176.ftz, 917 kB).

Here is a small helper module for the decisions above. The detector is deliberately simple, to show where simple fails.

// UI locale and content language are separate values. Never derive one from the other silently.
const RTL = new Set(['ar', 'he', 'fa', 'ur']);

/** Rough script-based guess: enough to pick a direction and a prompt, not a language-ID model. */
export function guessLanguage(text) {
  const arabic = (text.match(/[؀-ۿݐ-ݿ]/g) || []).length;
  const latin = (text.match(/[A-Za-zÀ-ÿ]/g) || []).length;
  if (arabic + latin < 3) return 'und';
  if (arabic / (arabic + latin) > 0.6) return 'ar';
  if (arabic / (arabic + latin) > 0.2) return 'mixed';
  return /[ñ¿¡áéíóú]|\b(el|la|los|las|de|que|por|para|está|dónde)\b/i.test(text) ? 'es' : 'en';
}

/** Wrap user or model text for display inside UI text of either direction (W3C: bdi / dir="auto"). */
export const isolate = (s) => `<bdi>${s.replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c])}</bdi>`;

/** Plain-text equivalent for places with no markup (notifications, CSV, SMS): FSI ... PDI. */
export const isolateText = (s) => `⁨${s}⁩`;

export function formatters(uiLocale) {
  return {
    dir: RTL.has(new Intl.Locale(uiLocale).language) ? 'rtl' : 'ltr',
    number: new Intl.NumberFormat(uiLocale),
    date: new Intl.DateTimeFormat(uiLocale, { dateStyle: 'long', timeZone: 'UTC' }),
    plural: new Intl.PluralRules(uiLocale),
  };
}

/** Normalise digits a user typed before parsing: Arabic-Indic and Persian to ASCII. */
export const toAsciiDigits = (s) =>
  s.replace(/[٠-٩]/g, (d) => d.charCodeAt(0) - 0x0660).replace(/[۰-۹]/g, (d) => d.charCodeAt(0) - 0x06F0);

/** System prompt: the answer language comes from the content, or the user's explicit choice, not the UI. */
export function systemPrompt({ answerLanguage }) {
  const name = { ar: 'Arabic', en: 'English', es: 'Spanish' }[answerLanguage] ?? 'the language of the user\'s message';
  return `Answer in ${name}. Keep product names, code, URLs and numbers exactly as written.`;
}

We ran it in Node 24. It labelled وين طلبي؟ as ar, “¿Dónde está mi pedido?” as es, “Where is my order?” as en, and an Arabic sentence containing the code ORD-5521 as ar. “ok” came back und, which correctly falls back to “the language of the user’s message” in the prompt. And “ana 3ayez a3raf el order fen”, Egyptian Arabic in Latin letters (Arabizi), came back es, because the word “el” looks Spanish. That is the honest result for a heuristic. If your users write Arabizi, detect it explicitly and treat it as Arabic, as in handling Arabizi, and let users correct the answer language with one tap.

The digit helper turned ٢٠٢٦-١١-١٥ into 2026-11-15, and isolate() escaped HTML before wrapping, so a company name like Acme <Ltd> can’t inject markup.

What else changes when the language changes?

  • Text length. Translated interface text is often longer. The W3C cites IBM guidelines expecting English strings of up to 10 characters to grow to 200–300% of their length in European languages, and strings over 70 characters to about 130%. Design buttons and labels to wrap, and test the Spanish build at narrow widths.
  • Fonts. Choose a font family with a matching Arabic design, and check Arabic line height: diacritics need room above and below.
  • Search and matching. Arabic text needs normalisation before matching (diacritics, alef forms, tatweel). The Arabic text normalizer shows each rule.
  • Speech. Pick the transcription model by the audio’s language, not the interface. BroadNet lists one Arabic model and one 14-language model that covers English, Spanish and Arabic; its multilingual model page says to choose the Arabic model for Arabic audio. The multilingual speech-to-text post compares the options.
  • Dialect. “Arabic” is not one target. Users in Riyadh, Cairo and Casablanca write differently; Gulf and Egyptian dialects covers what to test.

How do you evaluate and budget each language?

Separately. One combined score hides a weak language, and one combined budget hides an expensive one.

Build a small evaluation set per language from real messages, with native speakers labelling the expected answers. Check that the answer is in the requested language, that names, numbers and codes survive unchanged, and that quality holds for each dialect you serve. Run the same set when you change model or prompt; the method is in evaluating an LLM before switching.

For cost, token counts differ by language and tokenizer. In BroadRouter’s measured dataset, the same Modern Standard Arabic text needs 1.31× (Qwen3.8 27B) to 1.77× (GLM 5.3) the tokens of its English translation. Real cost by language turns those counts into money per model, including Spanish, and the Arabic token counter measures your own text. Log tokens per request with the content language attached, and you can see cost per language per user, not just per month.

Finally, get native review before launch. Machine translation and model output both produce Arabic and Spanish that is grammatical but wrong for your audience. A reviewer who uses the product in their own language catches what no test does.

Where BroadNet Inference fits

BroadRouter is BroadNet’s own site. BroadNet Inference’s models are a reasonable fit for an Arabic, English and Spanish product: BroadNet reports testing Qwen3.8 27B in Arabic, including Gulf and Egyptian dialect understanding; Gemma 4 VL 26B runs on the $5 starting credit; and transcription covers Arabic (BroadNet Transcribe Arabic, $0.0042 per minute) and 14 languages including English and Spanish (BroadNet Transcribe, $0.002 per minute). Inference content is not retained; necessary account, billing and security metadata is retained as described in BroadNet’s privacy statement. Everything in this post about layout, direction, formatting and detection is your application’s job, whichever API you use.

Questions

Should the AI answer in the interface language or the user's language?

Default to the language of the user's message, and let the user override it. The interface locale only tells you how to lay out the screen. An Arabic interface user who types in English usually wants an English answer.

How do I display English text inside an Arabic chat bubble?

Give each message element dir="auto" so the browser sets its direction from the first strong character, and wrap inserted names, codes and URLs in a bdi element. In plain text, wrap them in U+2068 FIRST STRONG ISOLATE and U+2069 POP DIRECTIONAL ISOLATE.

Should Arabic users see Arabic-Indic digits?

It depends on the region and your users. In our Node 24 test, the default for ar-SA and ar-EG was Arabic-Indic digits and for ar-AE and ar-MA Western digits. Pick per locale, offer a setting, and accept both on input by normalising digits before parsing.

How do I detect the language of a chat message?

For Arabic versus Latin script, counting characters in the Arabic Unicode block works. For telling English from Spanish, or handling short or mixed messages, use a trained language-ID model such as fastText's lid.176, and still treat the result as a hint.

Does Arabic cost more than English with an LLM API?

Often, per message, because many tokenizers need more tokens for the same Arabic content. The ratio depends on the model's tokenizer. Measure it on your own text and budget each language separately.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity