How to Work with Localization

Estimated reading: 4 minutes 39 views

Overview

Flutter Dashboard UI Kits uses Flutter’s built-in Localization system along with the intl package. All translatable strings are managed inside the auto-generated file, lib/generated/l10n.dart. This allows your dashboard to support multiple languages easily (English, Indonesian, etc.).

Localization File Structure

Localization files are stored under:

Dart
lib/l10n/

Typical files:

Dart
lib/l10n/
 ├── intl_en.arb
 ├── intl_id.arb
 └── intl_...(other language).arb

Each .arb file contains key–value pairs, for example:

intl_en.arb

Dart
{
  "dashboard": "Dashboard",
  "reports": "Reports",
  "settings": "Settings"
}

intl_id.arb

Dart
{
  "dashboard": "Dasbor",
  "reports": "Laporan",
  "settings": "Pengaturan"
}

Flutter will auto-generate the translations into:

Dart
generated/l10n.dart

How to Add a New Language

Step 1 — Create a new ARB file

Example for Spanish:

Dart
lib/l10n/intl_es.arb

Add translations:

Dart
{
  "dashboard": "Panel",
  "reports": "Informes",
  "settings": "Configuración"
}

Step 2 — Regenerate translation file

Run:

Dart
dart run intl_utils:generate

This updates:

Dart
lib/generated/l10n.dart

Step 3 — Add language to Language Selector

A Language Selector is a User Interface (UI) element that allows users to easily choose and change the display language of a website, application, or digital platform. Its primary function is to enhance global accessibility and improve User Experience (UX) by enabling multilingual support, ensuring that interface texts, labels, and content are displayed in the language most familiar to the user. In FlutKit Dashboard UI Kits, this selector appears as a dropdown menu at top navigation bar.

Open:

Dart
/lib/views/widgets/advanced_ui/top_nav_bar_widget.dart

Find and add new translation configuration:

Dart
const localeMenuConfigs = [
  LocaleMenuConfig(
    languageCode: 'en',
    name: 'English',
  ),
  LocaleMenuConfig(
    languageCode: 'id',
    name: 'Indonesia',
  ),

  // add new translation config here
  LocaleMenuConfig(
    languageCode: 'es', // Spanish Code
    name: 'Español',    // Spanish language name
  ),
];

Localization is now ready, user can select to new added translation. Currently, this utilizes mockup data. You can create services based on this data structure to integrate with your actual backend.

Step 4 — Set default language (optional)

To set the default language for your dashboard, follow these simple steps. This process ensures that your app starts with your preferred language automatically when a user opens it for the first time.

1. Locate the Configuration File

Open your project folder and navigate to the following directory:
lib > configs > global_config.dart

2. Find the Locale Variable

Look for the line of code that defines the defaultLocale. It should look like this:

Dart
static const String defaultLocale = "en";

3. Update the Language Code

Replace the value inside the quotation marks ("en") with your desired language’s ISO 639-1 code.

  • For example, if you want to set the default language to Indonesian, change it to:
Dart
static const String defaultLocale = "id";
  • If you want Spanish, change it to:
Dart
static const String defaultLocale = "es";

4. Save and Restart

After making the change, Save (Ctrl+S) the file. To see the changes take effect in your app, perform a Hot Restart or rebuild the application.

Common Language Codes

Here is a quick reference table for common language codes:

LanguageCode
Englishen
Indonesianid
Spanishes
Frenchfr
Arabicar
Chinesezh

Note: Ensure that the language code you choose is also supported in your translation files (located in lib/l10n/), otherwise the app may default back to English or show missing text.

How to Use Translated Text in Widgets

To access any translation:

Dart
Lang.of(context).dashboard

Example:

Dart
Text(Lang.of(context).dashboard);

This automatically switches based on the active locale.

Share this Doc

How to Work with Localization

Or copy link

CONTENTS