Skip to content

Internationalization (i18n)

Mateu passes the user-visible strings it derives from your declarations — field labels, page titles, validation messages, button texts, alerts — through a bean implementing the Translator interface. This centralizes translation in a single extension point. Text you place in a fluent component tree yourself (a Text’s text, for instance) travels as written: translate it in your own code, e.g. with the same Translator bean.

🎬 Mateu deep dives: Internationalisation — on YouTube

public interface Translator {
String translate(String text, HttpRequest httpRequest);
}
ParameterDescription
textThe original string (as it appears in code or in annotations)
httpRequestRequest context — lets you read the Accept-Language header, session cookies, or anything else needed to resolve the locale

The returned value is the string sent to the frontend.


The core module ships an implementation based on standard Java i18n (ResourceBundle). To use it, just add a messages file to the classpath:

src/main/resources/
messages.properties ← default locale
messages_es.properties ← Spanish
messages_fr.properties ← French
...

Example messages_es.properties:

Name=Nombre
Save=Guardar
Order\ #=Número de pedido
Field\ is\ required=El campo es obligatorio

The locale is resolved from the Accept-Language header of the HTTP request.


To replace the default implementation, register a bean implementing Translator with higher priority. In Spring Boot:

@Component
@Primary
public class DatabaseTranslator implements Translator {
final TranslationRepository repo;
@Override
public String translate(String text, HttpRequest httpRequest) {
String locale = httpRequest.getHeaderValue("Accept-Language");
return repo.findTranslation(text, locale)
.orElse(text); // fall back to the original text
}
}

In Quarkus or Micronaut use the equivalent annotation (@Alternative + @Priority, @Primary, etc.).


The page language and the client’s own words

Section titled “The page language and the client’s own words”

Besides the texts your app sends (translated by the Translator), the web client draws some words by itself: dialog and toolbar buttons (Cancel, Retry, Save), the filter bar (Filter by, Clear filters), pagination, empty states, the command center, error toasts, upload/signature/camera widgets and accessible labels. They come from one catalogue in the client, in the page language.

The page language is decided on the server: the app shell carries AppDto.locale, which is what Translator.locale(HttpRequest) returns. The default translator answers the request’s Accept-Language; override locale to follow a user preference instead:

@Service
public class UserLanguageTranslator implements Translator {
final UserPreferences preferences;
public UserLanguageTranslator(UserPreferences preferences) { this.preferences = preferences; }
@Override public String translate(String text, HttpRequest rq) { /* … */ return text; }
@Override public String locale(HttpRequest rq) { // e.g. "es"
return preferences.languageOf(rq.getUserPrincipal().getName());
}
}

The client sets it on <html lang> (so screen readers, hyphenation and spell-check follow it too) and draws its chrome in it. Without an app shell, or when locale returns null, the browser’s language is used. The catalogue speaks English, Spanish, French, German, Portuguese and Italian, chosen by the tag’s primary subtag (pt-BR and pt-PT → Portuguese, de-AT → German, fr-CA → French); any other language falls back to English. The Portuguese is written the Brazilian way (Salvar, Excluir, tela). (.NET: ITranslator.Locale; Python: Translator.locale().)

The same six languages are spoken by every renderer that draws words of its own: the web client (Vaadin), Redwood, the React Native app (task ETAs, the version notice, the hub’s update notices) and the IntelliJ plugin (notice actions, the inbox, task ETAs, the version notice).

The words the server writes for you — a crud’s New, Save, Cancel, Edit, Delete, Back to list, Add another, the wizard’s Save and close, the calendar’s Today — go through your Translator first, so you can translate or rename them (or override the crud’s saveLabel(), newLabel()…). When your translator leaves one as it is, Mateu answers it in the same language as the client’s chrome (Translator.locale, else Accept-Language) from a small catalogue of its own: Spanish, French, German, Portuguese or Italian, English otherwise. The not-found page follows the browser’s language the same way. A label you write yourself is never touched. (This server-side catalogue is Java’s: the .NET and Python servers send these built-in labels in English and leave the rest to your translator.)

An app that speaks one language whatever the browser says (a Spanish back office used from machines set up in English) sets mateu.locale:

mateu.locale=es

or MATEU_LOCALE=es in the environment (.NET: MateuOptions.Locale or MATEU_LOCALE; Python: add_mateu(app, …, locale="es") or MATEU_LOCALE). The value is a BCP 47 tag: es, en-GB, pt-BR (pt_BR is read too). With it set, every request gets that language instead of its Accept-Language: AppDto.locale (so <html lang>, the client’s own words and money formatting), the words the server writes for you, the not-found page, bean-validation messages and what ${i18n.…} resolves for. Without it nothing changes: the browser decides.

A Translator that overrides locale(...) still wins over the setting (a per-user preference beats the app-wide default); one that returns null leaves it to the setting. A value that is not a language tag is ignored, with one warning in the log.

Date fields are written and read in the page language too: the Vaadin date pickers and Redwood’s oj-input-date / oj-input-date-time (forms, drawers, the row editor, range filters) take the order and separator from it, refined by the browser’s region (es + es-MX) — 15/2/2041 in Spanish, 2/15/2041 in US English.

Mateu does not support right-to-left languages (Arabic, Hebrew, Persian, Urdu) in 3.0. Nothing sets dir="rtl", and the chrome catalogue has no RTL language, so an RTL request falls back to English. What would have to change, renderer by renderer:

  • Web (Vaadin). <html dir="rtl"> would have to follow the UI language (applyUiLanguage, the one place that sets <html lang>). Vaadin’s own components mirror under dir="rtl", but Mateu’s own elements mostly do not: the shared library’s styles use physical properties (margin-left, padding-right, left:/right:, text-align: left) roughly ten times more often than logical ones (margin-inline-start, inset-inline-end), so drawers, the filter bar’s panel, FABs, the command center, the sticky index (@Toc), zones and the Gantt / planning board would sit on the wrong side. Arrow-key handling (ArrowLeft/ArrowRight in grids, tabs and the board) and slide transitions (translateX) would need flipping. The chat panel already reads the computed direction.
  • Redwood. Oracle JET and Spectra support RTL through the page’s dir attribute, and the app’s own stylesheet is already mostly logical; the bridge would need to set dir with the language, and the pieces Mateu draws itself (the anchor navigator, the folded foldout strips, the map and calendar fallbacks) would need checking.
  • React Native. It would need I18nManager.allowRTL/forceRTL (an app restart) and a review of every left/right style and row direction; none of that is wired today.
  • IntelliJ plugin. Swing mirrors with ComponentOrientation.RIGHT_TO_LEFT; the plugin never sets it, and its own layouts assume left-to-right.

Text in an RTL language still displays (the browser’s bidirectional algorithm handles a field’s value), but the layout around it does not mirror.

ScenarioSuggested implementation
Translations in .properties filesDefault implementation from core
Translations in a database (hot-editable)@Primary bean querying the DB
Per-tenant / white-label labelsRead the tenant from the request and resolve the matching bundle
External translation serviceAPI call with a local cache to keep latency low
Development mode without translationsReturn text directly (pass-through)

Your Translator implementation is invoked for every string of every response. If resolution involves DB or network access, add a cache layer keyed by (text, locale):

@Component
@Primary
public class CachedDatabaseTranslator implements Translator {
final TranslationRepository repo;
final Cache<String, String> cache = Caffeine.newBuilder().maximumSize(10_000).build();
@Override
public String translate(String text, HttpRequest httpRequest) {
String locale = locale(httpRequest);
return cache.get(text + "|" + locale,
k -> repo.findTranslation(text, locale).orElse(text));
}
}

  • Security — authentication and role-based authorization
  • Key interfaces — full reference of public interfaces

The default translator also reads the YAML message catalogues (specs/ui/translations/<locale>.yaml or type: Translations): ${i18n.key} inside a label, or a label that is a key of the catalogue, is translated for the request’s locale. A TranslationsSupplier bean contributes messages from code. See Translations in YAML.