Languages

spring.flutter.navigation.languages gives each language its own addresses. The first language is the default, without a prefix; the others put theirs under /<language>. /ja/catalog opens the /catalog screen with the app's locale set to Japanese, so context.message, screen titles and Flutter's own widgets follow.

Why

On the web a language should be part of the address: a link shared in Japanese opens in Japanese, search engines list each language's pages, and the back button returns to the language it came from. The app's own code writes its paths without a prefix and keeps the current language, so no screen needs to know about it.

Example

# lib/resources/application.yml
spring:
  flutter:
    navigation:
      languages: [en, ja]
// The current language stays: /catalog in English, /ja/catalog in Japanese.
context.route.go('/catalog');

// A menu that shows the same screen in another language.
TextButton(
  onPressed: () => context.route.switchLanguage('ja'),
  child: const Text('日本語'),
);

The rules

LanguageChangedEvent

The navigation publishes a LanguageChangedEvent when the language switches, by the address or by switchLanguage:

// Loads the catalog of the new language.
@Component()
class CatalogLanguage {
  CatalogLanguage(this.catalog);

  final Catalog catalog;

  @EventListener()
  void changed(LanguageChangedEvent event) => catalog.reload(event.to);
}
Field Meaning
from The language before; null before the first one was set
to The language now

The texts of the screens change with it; ThemeText of the Flutter starter changes them the theme's way (motion.text-change).

The property

Key Type Default Meaning
spring.flutter.navigation.languages list of language tags none: one language, no prefix The languages with their own addresses, the default first

Unlike spring.flutter.app.locales, this key is a real list: [en, ja] in YAML or en,ja in .properties. The app's locales still come from the message files or spring.flutter.app.locales (see Messages and languages).

See also