A simple Flutter application demonstrating multi-language support using the provider and shared_preferences packages.
- Multi-language support (English, Hindi, Marathi)
- Persisting selected language using
SharedPreferences - Localization using
flutter_localizationsandflutter_gen
- Flutter SDK
-
Clone the repository:
git clone https://github.com/your-username/multi_language_app.git
-
Navigate to the project directory:
cd multi_language_app -
Install dependencies:
flutter pub get
-
Generate localization files:
flutter pub run intl_utils:generate
-
Run the application:
flutter run
main.dart: Entry point of the application, sets up theLanguageProviderandMaterialApp.language_provider.dart: Provides the selected language and persists it usingSharedPreferences.login_page.dart: Example login page with language selection dropdown.lib/l10n: Directory containing localization files (app_en.arb,app_hi.arb,app_mr.arb).
The localization files are placed in the lib/l10n directory. Each file contains key-value pairs for the text used in the application.
Example (app_en.arb):
{
"helloWorld": "Hello World!",
"counterMsg": "You have pushed the button this many times:",
"signIn": "Sign In",
"heading": "Hotstar",
"emailHint": "Email or Phone number",
"passHint": "Password",
"forgotPass": "Forgot Password?",
"loginBtn": "Login",
"txtNoAcc": "Don't have an account?",
"txtSignUp": "Sign Up with",
"google": "Google",
"facebook": "Facebook",
"twitter": "Twitter"
}
## Adding a New Language ##
1.Create a new .arb file in the lib/l10n directory, e.g., app_es.arb for Spanish.
2.Add the necessary key-value pairs for the new language.
3.Update the supportedLocales list in main.dart to include the new locale:
supportedLocales: const [
Locale('en'),
Locale('hi'),
Locale('mr'),
Locale('es'), // Spanish
],
4.Generate the localization files:
flutter pub run intl_utils:generate
## Contributing
Contributions are welcome! Please open an issue or submit a pull request with your changes.
License
This project is licensed under the MIT License - see the LICENSE file for details.