Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multiple Language support added #1071

Open
wants to merge 2 commits into
base: flutter_app
Choose a base branch
from

Conversation

Dhruv80576
Copy link
Contributor

@Dhruv80576 Dhruv80576 commented Nov 3, 2024

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

Screen_recording_20241103_180601.mp4

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:

  • Add support for multiple languages, including Chinese, to the application.

Enhancements:

  • Implement a localization system using JSON files for language translations.

Copy link

sourcery-ai bot commented Nov 3, 2024

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
Loading

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 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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Dhruv80576 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider creating a constants file for translation keys (e.g., translation_keys.dart) to avoid string literals and make maintenance easier. This would help prevent typos and make refactoring simpler.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

// Method to translate a key into a localized string
String translate(String key) => _localizedStrings[key] ?? "";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding debug logging for missing translation keys

In debug mode, log a warning when a translation key is missing to help catch issues during development.

Suggested change
String translate(String key) => _localizedStrings[key] ?? "";
String translate(String key) {
final value = _localizedStrings[key];
if (value == null) {
assert(() {
print('Missing translation key: $key');
return true;
}());
}
return value ?? '';
}

@adityastic
Copy link
Collaborator

I think we can hop onto a different and scalable solution. More info: #927

@Jhalakupadhyay Jhalakupadhyay changed the title Multiple Language support added feat: Multiple Language support added Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Settings not changing
2 participants