Skip to content

A Flutter Localisation Demo project showcasing multi-language support, dynamic language switching.

Notifications You must be signed in to change notification settings

iamtvirani/localisation_demo

Repository files navigation

Localization Demo App

This Flutter application demonstrates multi-language support using the intl package. It includes a dynamic language switching feature, allowing users to select their preferred language from a dropdown menu. The app's interface updates instantly based on the selected locale.

Features

  • Multi-Language Support: Supports English, Hindi, and Gujarati. Translates UI text dynamically based on user selection.
  • Dynamic Language Switching: Dropdown menu in the app bar for selecting a language. Changes language instantly without restarting the app.
  • Localized Texts: Includes common phrases like "Welcome Back", "Hello", "Welcome Message", and "Introduction" that are translated into the supported languages.

How It Works

  1. The app uses ValueNotifier to manage the current locale dynamically.
  2. intl and flutter_localizations packages are used for localization setup.
  3. A dropdown in the app bar allows users to select a language (English, Hindi, or Gujarati).
  4. Text widgets in the app retrieve translations using the S.of(context) generated delegate.

Code Highlights

Global Locale Management

      
ValueNotifier localeNotifier = ValueNotifier(const Locale('en'));

    

Manages the selected language globally across the app.

Dropdown for Language Selection


DropdownButton<Locale>(
  value: localeNotifier.value,
  onChanged: (Locale? newLocale) {
    if (newLocale != null) {
      localeNotifier.value = newLocale;
    }
  },
  items: const [
    DropdownMenuItem(value: Locale('en'), child: Text('English')),
    DropdownMenuItem(value: Locale('hi'), child: Text('Hindi')),
    DropdownMenuItem(value: Locale('gu'), child: Text('Gujarati')),
  ],
)
 

Localized Strings


Text(S.of(context).welcome_back);

  

Setup and Run

  1. Clone the repository.
  2. Run the following command to generate localization files:
  3. flutter pub run intl_utils:generate
  4. Launch the app:
  5. flutter run

Folder Structure


lib/
├── generated/              # Localization files generated by intl
├── screen/                 # Screens of the app
│   └── localization_page.dart
├── main.dart               # Entry point of the app

    

Dependencies

  • flutter_localizations: Provides localization support for Flutter widgets.
  • intl: Enables internationalization for text, date, and number formatting.

This project serves as a foundation for implementing localization in Flutter applications, making it easier to create apps for a global audience.

Screenshots:

Screenshot 2024-11-29 at 12 09 05 PM Screenshot 2024-11-29 at 12 09 14 PM Screenshot 2024-11-29 at 12 09 21 PM

Happy coding :)

About

A Flutter Localisation Demo project showcasing multi-language support, dynamic language switching.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published