ConfigurationInternationalization (i18n)

GLOBALIZATION

Internationalization (i18n)

Invenicum supports multiple languages out of the box with Flutter’s built-in i18n system, allowing UI adaptation on-the-fly.


Overview

The localization system is built on Application Resource Bundle (ARB) files, enabling a scalable way to manage translations across the entire application.

English

en

English

Spanish

es

Español

Italian

it

Italiano

Portuguese

pt

Português

French

fr

Français

German

de

Deutsch

Default language: Spanish (es)

Localization Configuration

l10n.yaml

Located in l10n.yaml:1-11.

arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
supported-locales:
  - en, es, it, pt, fr, de

main.dart Registration

MaterialApp.router(
  locale: preferencesProvider.locale,
  localizationsDelegates: const [
    AppLocalizations.delegate,
    GlobalMaterialLocalizations.delegate,
  ],
)

ARB File Structure

File: lib/l10n/app_en.arb

”@@locale”: “en”,

“appTitle”: “Invenicum Inventory”,
“dashboard”: “Dashboard”,
“@fieldRequiredWithName”: {
  “placeholders”: {
    “field”: { “type”: “String” }
  }
},
“fieldRequiredWithName”: “Field “{field}” is required.”

Programmatic Usage

Preferences Provider

lib/providers/preferences_provider.dart

Future<void> setLanguage(String languageCode) async {
  await _preferencesService.updateLanguage(languageCode);
  notifyListeners();
}

Using Translations in Code

// Simple string

AppLocalizations.of(context)!.dashboard

// With placeholders

l10n.fieldRequiredWithName(“Email”)

Adding a New Language

1. Update Config

Add the new locale code (e.g., ‘ja’) to the supported-locales list in l10n.yaml.

2. Create ARB

Create lib/l10n/app_ja.arb and translate all keys from the English template.

3. UI Selection

Add the new language option to the dropdown in the Settings screen.

4. Generate

Run flutter gen-l10n to generate the necessary language-specific classes.

Best Practices

Use Descriptive Keys: Instead of text1, use dashboardTitle or errorLoadingData to maintain clarity.

Keep in Sync: When adding a new key, update all language files immediately to avoid missing translations in the UI.

Avoid Hardcoded Strings: Always use AppLocalizations for user-facing text, including placeholders and error messages.

Generated Files (Read-Only)

lib/l10n/app_localizations.dart (Base)
lib/l10n/app_localizations_en.dart
lib/l10n/app_localizations_es.dart
lib/l10n/app_localizations_fr.dart