Flutter UIKit Localization

Introduction#

The AppLocalization class is a custom localization solution designed to provide localized strings for your Flutter application. By integrating this class, you can easily manage and access localized content, starting with support for English.

Adding the AppLocalization Class to Your Project#

Ensure that the AppLocalization class is included in your project and import it as needed:

import 'package:mirrorfly_uikit_plugin/mirrorfly_uikit.dart';

Configuring Localization in Flutter#

To enable localization in your Flutter app, you need to configure several settings.

1. Update pubspec.yaml#

Add the Flutter localization package and specify the assets:

dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
# Include assets if using external localization files
flutter:
assets:
- assets/locales/

2. Modify main.dart#

Import the necessary packages and configure the MaterialApp widget to support localization.

import 'package:flutter/material.dart';
import 'package:mirrorfly_uikit_plugin/mirrorfly_uikit.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Your App',
// Add these lines
locale: Locale('en', 'US'), // Default locale
supportedLocales: AppLocalizations.supportedLocales,
localizationsDelegates: [
AppLocalization.delegate, // Custom delegate
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: HomePage(),
);
}
}

3. Add Supported Locales in AppLocalization#

/// Use this method to add the locale you want to support in the UIKIT Plugin.
AppLocalizations.addSupportedLocales(const Locale("Ta", "IN"));

4. Download Localization File#

Download the en.json file for the english language and save it in the assets/locales/ directory.
Download

Note: This document assumes that the AppLocalization class and associated localization files are correctly implemented and compatible with Flutter's localization framework.