fossasia / badgemagic-android

Badge Magic with LEDs - Android App https://play.google.com/apps/testing/org.fossasia.badgemagic
Apache License 2.0
1.85k stars 206 forks source link

feat: Multiple Language support added #1071

Open Dhruv80576 opened 3 weeks ago

Dhruv80576 commented 3 weeks ago

Fix #1067 Setting now updated, added language switch option. Now this application supports chinese language also. Please find the video attached.

https://github.com/user-attachments/assets/a03e73af-0ae0-4908-906b-ef24d04b1dca

Summary by Sourcery

Add multiple language support to the application, including a language switch option and support for Chinese. Implement a localization system to manage translations using JSON files.

New Features:

Enhancements:

sourcery-ai[bot] commented 3 weeks ago

Reviewer's Guide by Sourcery

The pull request implements multi-language support by adding a localization system that currently supports English and Chinese languages. The implementation uses Flutter's localization framework with JSON-based translation files and includes a locale provider to manage language switching.

Class diagram for localization implementation

classDiagram
    class AppLocalizations {
        +Locale? locale
        +Map<String, String> _localizedStrings
        +Future loadJsonLanguage()
        +String translate(String key)
        +String translateWithArgs(String key, Map<String, dynamic> args)
    }
    class _AppLocalizationsDelegate {
        +bool isSupported(Locale locale)
        +Future<AppLocalizations> load(Locale locale)
        +bool shouldReload(LocalizationsDelegate old)
    }
    class LocaleProvider {
        +Locale _locale
        +Locale get locale()
        +void changeLocale(Locale newLocale)
    }
    AppLocalizations --> _AppLocalizationsDelegate : delegate
    AppLocalizations --> Locale : locale
    LocaleProvider --> Locale : manages
    AppLocalizations --> "1" Map : _localizedStrings

File-Level Changes

Change Details Files
Added localization infrastructure and translation system
  • Created AppLocalizations class to handle translations
  • Implemented LocaleProvider to manage language state
  • Added language JSON files for English and Chinese translations
  • Set up localization delegates and supported locales in MaterialApp
lib/providers/app_localisation.dart
lib/providers/locale_provider.dart
lib/main.dart
assets/lang/en.json
assets/lang/zh.json
Updated UI components to use translated strings
  • Replaced hardcoded strings with translation keys
  • Added translation extension method for easy string translation
  • Updated navigation drawer text to use translations
  • Modified home screen tabs to use translated labels
lib/view/widgets/navigation_drawer.dart
lib/view/widgets/homescreentabs.dart
lib/view/homescreen.dart
Added language selection functionality in settings
  • Implemented language switching dropdown in settings screen
  • Added language mapping between display names and locale codes
  • Connected language selection to LocaleProvider
lib/view/settings_screen.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#1067 Implement language switching functionality in the settings

Possibly linked issues


Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
adityastic commented 3 weeks ago

I think we can hop onto a different and scalable solution. More info: https://github.com/fossasia/badgemagic-android/issues/927