Building a Darija Translator: Jakarta REST, an LLM, and Four Clients
I built a secured REST service that translates any language into Moroccan Darija with an LLM, plus four clients that call it: a Chrome extension, a PHP site, a Python app and a React Native mobile app. Darija is the everyday language of more than 30 million people, but most translation tools only offer Modern Standard Arabic (Fus7a). Fus7a is what you read in the news, not what you say at the…
The author developed a secure REST service capable of translating any language into Moroccan Darija and created four clients: a Chrome extension, a PHP website, a Python application, and a React Native mobile app. Darija is the everyday language spoken by over 30 million people, but many translation tools only offer Modern Standard Arabic.
The server, built using Jakarta EE 10 APIs and the JDK, runs as a WAR on Payara Micro, an embedded Jakarta EE runtime, requiring no separate application server. The security is handled through Jakarta Security and a custom IdentityStore for authentication, with a single HTTP Basic authentication mechanism.
The core of the project involves an LLM interface with two implementations: a Google Gemini client and an Ollama client for running local models. The prompt engineering plays a crucial role in generating Darija translations instead of Fus7a. The system instruction provided to the LLM ensures the output is in the Moroccan Darija dialect, using specific anchors and avoiding formatting or notes.
The Chrome extension requires manually selecting text, opening a side panel, and translating the text. The speech-to-text function and voice-to-voice mode were challenging to implement due to Chrome's restrictions. The other clients follow a similar thin layer over the HTTP call, offering PHP web forms and command-line scripts, a Python command-line interface, and a React Native mobile app.
Future improvements could include implementing token-based authentication, streaming translations for long texts, and adding reverse translation from Darija to English or French.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.