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

new feature🦄: introduced localization to donnorconnect #61

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-localization-file: app_localizations.dart
nullable-getter: false
59 changes: 59 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"how_can_we_help": "How can we help you?",
"donate": "Donate",
"required": "Required",
"locate_nearby_bloodbank": "Locate Nearby Bloodbanks",
"find_nearby_bloodbank": "Find Nearby BloodBank.",
"learn_about_donating": "Learn About Donating",
"learn_more_about_donating": "Learn more about blood & platelet donation.",
"locate_blood_bank": "Locate Blood Banks",
"city": "City",
"district": "District",
"state": "State",
"contact": "Contact",
"email": "Email",
"nodal_officer": "Nodal Officer",
"contact_nodal_officer": "Contact Nodal Officer",
"category":"Category",
"no_data_available": "No data available.",
"error": "Error",
"home": "Home",
"search": "Search",
"camps": "Camps",
"profile": "Profile",
"welcome_to_your_profile": "Welcome to your profile",
"medical_history": "Medical History",
"current_medications": "Current Medications",
"allergies": "Allergies",
"blood_type": "Blood Type",
"organ_donor": "Organ Donor",
"blood_donor": "Blood Donor",
"enable_donation_notifications": "Enable Donation Notifications",
"profile_saved": "Profile Saved",
"save_profile": "Save Profile",
"please_enter_your_email_and_password": "Please enter your email and password",
"welcome_back": "Welcome Back",
"log_in_to_your_account": "Log in to your account",
"please_enter_email": "Please enter Email",
"password": "Password",
"please_enter_password": "Please enter Password",
"forget_password": "Forgot password?",
"login": "Login",
"signup": "Sign up",
"do_not_have_account": "Do not have the account?",
"password_dont_match": "Passwords do not match",
"full_name": "Full name",
"phone_number": "Phone number",
"create_password": "password number",
"confirm_password": "Confirm password",
"availabel_for_organ_donation": "Available for Organ Donation",
"avilabel_for_blood_donation": "Available for Blood Donation",
"by_sign_your_account_you_agree_terms_and": "By signing you agree to terms and",
"use_and_the_privacy_notice": "use and the privacy notice",
"password_error_text": "Password must be 8 character long and must have aleast 1 uppercase,1 Lowercase,1 digit,1 special character",
"phone_number_error_text":"Phone number must be of 10 Digit",
"name_field_error_text":"Name can not be Empty",
"email_field_error_text":"Email is Wrong or Blank, Kindly Enter correct Email",
"create_account":"Create your new account",
"register":"Register"
}
59 changes: 59 additions & 0 deletions lib/l10n/intl_gu.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"how_can_we_help": "અમે તમને કેવી રીતે મદદ કરી શકીએ?",
"donate": "દાન કરો",
"required": "જરૂરી",
"locate_nearby_bloodbank": "નજીકની બ્લડ બેંક શોધો.",
"find_nearby_bloodbank": "નજીકની બ્લડ બેંક શોધો.",
"learn_about_donating": "જાણો દાન વિશે",
"learn_more_about_donating": "રક્ત અને પ્લેટલેટ દાન વિશે વધુ જાણો.",
"locate_blood_bank": "તમારી બ્લડ બેંક શોધો",
"city": "શહેર",
"district": "જિલ્લો",
"state": "રાજ્ય",
"contact": "સંપર્ક",
"email": "ઇમેઇલ",
"nodal_officer": "નોડલ અધિકારી",
"contact_nodal_officer": "નોડલ અધિકારીનો સંપર્ક કરો.",
"no_data_available": "ડેટા અસ્તિત્વમાં નથી.",
"error": "ભૂલ",
"home": "હોમ પેજ",
"search": "શોધો",
"camps": "શિબિર",
"profile": "પ્રોફાઇલ",
"welcome_to_your_profile": "તમારી પ્રોફાઇલમાં આપનું સ્વાગત છે.",
"medical_history": "તબીબી ઇતિહાસ",
"current_medications": "હાલની દવાઓ",
"allergies": "એલર્જી",
"blood_type": "લોહીનો પ્રકાર",
"organ_donor": "અંગ દાતા",
"blood_donor": "રક્તદાતા",
"enable_donation_notifications": "દાન સૂચનાઓ સક્રિય કરો",
"profile_saved": "રૂપરેખા સાચવવામાં આવી",
"save_profile": "પ્રોફાઇલ સાચવો",
"please_enter_your_email_and_password": "કૃપા કરીને તમારું ઈ-મેલ અને પાસવર્ડ દાખલ કરો.",
"welcome_back": "ફરી સ્વાગત છે",
"log_in_to_your_account": "તમારા એકાઉન્ટમાં લોગ ઇન કરો",
"please_enter_email": "ઇમેઇલ સબમિટ કરો",
"password": "પાસવર્ડ",
"please_enter_password": "મહેરબાની કરીને પાસવર્ડ દાખલ કરો",
"forget_password": "તમારો પાસવર્ડ ભૂલી ગયા છો?",
"login": "પ્રવેશ કરો",
"signup": "સાઇન અપ કરો",
"do_not_have_account": "ખાતું નથી?",
"password_dont_match": "પાસવર્ડ મેળ ખાતો નથી",
"full_name": "સંપૂર્ણ નામ",
"phone_number": "ફોન નંબર",
"create_password": "પાસવર્ડ નંબર",
"confirm_password": "પાસવર્ડની પુષ્ટિ કરો",
"availabel_for_organ_donation": "દાન માટે ઉપલબ્ધ",
"avilabel_for_blood_donation": "રક્તદાન માટે ઉપલબ્ધ",
"by_sign_your_account_you_agree_terms_and": "કરાર પર હસ્તાક્ષર કરીને, તમે શરતોથી સંમત થાઓ છો અને",
"use_and_the_privacy_notice": "ઉપયોગ અને ગોપનીયતા સૂચના",
"password_error_text": "પાસવર્ડ 8 અક્ષરો લાંબો હોવો જોઈએ અને તેમાં 1 અપરકેસ, 1 લોઅરકેસ, 1 અંક, 1 વિશેષ અક્ષર હોવો જોઈએ.",
"phone_number_error_text": "ફોન નંબર 10 અંકોનો હોવો જોઈએ.",
"name_field_error_text": "નામ ખાલી ન હોઈ શકે.",
"email_field_error_text": "ઈ-મેલ ખોટો અથવા ખાલી છે. મહેરબાની કરીને સાચો ઈ-મેલ દાખલ કરો.",
"create_account": "નવું ખાતું બનાવો",
"register": "નોંધણી કરો",
"category":"શ્રેણી"
}
60 changes: 60 additions & 0 deletions lib/l10n/intl_hi.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"how_can_we_help": "हम आपकी मदद कैसे कर सकते हैं?",
"donate": "दान करें",
"required": "आवश्यक",
"locate_nearby_bloodbank": "पास के ब्लडबैंक का पता लगाएं",
"find_nearby_bloodbank": "नजदीकी ब्लडबैंक खोजें.",
"learn_about_donating": "दान के बारे में जानिए",
"learn_more_about_donating": "रक्त और प्लेटलेट दान के बारे में अधिक जानें।",
"locate_blood_bank": "ब्लड बैंकों का पता लगाएं",
"city": "शहर",
"district": "ज़िला",
"state": "राज्य",
"contact": "संपर्क",
"email": "ईमेल",
"nodal_officer": "नोडल अधिकारी",
"contact_nodal_officer": "नोडल अधिकारी से संपर्क करें",
"no_data_available": "कोई डेटा मौजूद नहीं.",
"error": "एरर",
"home": "होम",
"search": "खोज",
"camps": "शिविर",
"profile": "प्रोफ़ाइल",
"welcome_to_your_profile": "अपने प्रोफाइल में आपका स्वागत है",
"medical_history": "मेडिकल हिस्ट्री",
"current_medications": "वर्तमान दवाएं",
"allergies": "एलर्जी",
"blood_type": "रक्त प्रकार",
"category":"वर्ग",
"organ_donor": "अंग दान करने वाला",
"blood_donor": "रक्तदाता",
"enable_donation_notifications": "दान सूचनाएं सक्षम करें",
"profile_saved": "प्रोफ़ाइल सहेजी गई",
"save_profile": "प्रोफ़ाइल सहेजें",
"please_enter_your_email_and_password": "कृपया अपना ईमेल और पासवर्ड दर्ज करें",
"welcome_back": "वापस स्वागत है",
"log_in_to_your_account": "अपने अकाउंट में लॉग इन करें",
"please_enter_email": "ईमेल दाखिल करें",
"password": "पासवर्ड",
"please_enter_password": "कृपया पासवर्ड भरें",
"forget_password": "पासवर्ड भूल गया?",
"login": "लॉगइन",
"signup": "साइन अप करें",
"do_not_have_account": "खाता नहीं है?",
"password_dont_match": "पासवर्ड मेल नहीं खाता",
"full_name": "पूरा नाम",
"phone_number": "फोन नंबर",
"create_password": "पासवर्ड संख्या",
"confirm_password": "पासवर्ड की पुष्टि करें",
"availabel_for_organ_donation": "अंगदान के लिए उपलब्ध",
"avilabel_for_blood_donation": "रक्तदान के लिए उपलब्ध",
"by_sign_your_account_you_agree_terms_and": "हस्ताक्षर करके आप शर्तों पर सहमत हैं और",
"use_and_the_privacy_notice": "उपयोग और गोपनीयता नोटिस",
"password_error_text": "पासवर्ड 8 अक्षर लंबा होना चाहिए और इसमें 1 अपर केस, 1 लोअरकेस, 1 अंक, 1 विशेष अक्षर होना चाहिए",
"phone_number_error_text":"फोन नंबर 10 अंकों का होना चाहिए",
"name_field_error_text":"नाम रिक्त नहीं हो सकता",
"email_field_error_text":"ईमेल गलत या खाली है, कृपया सही ईमेल दर्ज करें",
"create_account":"नया खाता बनाएँ",
"register":"रजिस्टर"
}

17 changes: 17 additions & 0 deletions lib/language/cubit/language_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:donorconnect/language/helper/language.dart';
import 'package:donorconnect/language/services/language_repositoty.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// part '';
class LanguageCubit extends Cubit<Language> {
LanguageCubit() : super(Language.english);

void initilize() {
emit(LanguageRepository.getPrefferedLanguge());
}

// set
void changeLanguage(Language getlanguageFromUser) {
emit(getlanguageFromUser);
LanguageRepository.addPreferredLanguage(getlanguageFromUser);
}
}
45 changes: 45 additions & 0 deletions lib/language/helper/langauge_popup.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:donorconnect/language/cubit/language_cubit.dart';
import 'package:donorconnect/language/helper/language.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class LanguagePopup extends StatelessWidget {
const LanguagePopup({super.key});

@override
Widget build(BuildContext context) {
return BlocBuilder<LanguageCubit, Language>(
builder: (context, currentLangaugeState) {
return PopupMenuButton(
onSelected: (languageFromUser) {
context.read<LanguageCubit>().changeLanguage(languageFromUser);
},
itemBuilder: (context) => [
for (var values in Language.values)
PopupMenuItem(
value: values,
child: Row(
children: [
Text(values.countryFlag),
SizedBox(width: 16.0),
Text(values.languageName),
],
),
)
],
child: BlocBuilder<LanguageCubit, Language>(
builder: (context, currentLanguage) {
return Row(
children: [
Text(currentLanguage.countryFlag),
SizedBox(width: 16.0),
Text(currentLanguage.languageName),
Icon(Icons.arrow_drop_down_sharp),
],
);
},
),
);
});
}
}
15 changes: 15 additions & 0 deletions lib/language/helper/language.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum Language {
english(countryFlag: "🇮🇳", languageName: "English", languageCode: "en"),
hindi(countryFlag: "🇮🇳", languageName: "हिंदी", languageCode: "hi"),
gujarati(countryFlag: "🇮🇳", languageName: "ગુજરાતી ‍", languageCode: "gu");

final String countryFlag;
final String languageName;
final String languageCode;

const Language({
required this.countryFlag,
required this.languageName,
required this.languageCode,
});
}
6 changes: 6 additions & 0 deletions lib/language/helper/language_extention.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:flutter/material.dart' show BuildContext;
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

extension AppLocalizationExtention on BuildContext {
AppLocalizations get localizedString => AppLocalizations.of(this);
}
24 changes: 24 additions & 0 deletions lib/language/services/language_repositoty.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:donorconnect/language/helper/language.dart';
import 'package:shared_preferences/shared_preferences.dart';

class LanguageRepository {
static late SharedPreferences _prefs;
static Future<void> init() async {
_prefs = await SharedPreferences.getInstance();
}

// store language in local storage
static void addPreferredLanguage(Language language) {
_prefs.setString("language_key", language.languageCode);
}

// get stored language
static Language getPrefferedLanguge() {
final code = _prefs.getString("language_key");
for (var values in Language.values) {
if (values.languageCode == code) return values;
}
return Language
.english; // default to English if not found in stored languages
}
}
39 changes: 27 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:donorconnect/cubit/auth/auth_cubit.dart';
import 'package:donorconnect/cubit/locate_blood_banks/locate_blood_banks_cubit.dart';
import 'package:donorconnect/cubit/profile/profile_cubit.dart';
import 'package:donorconnect/firebase_options.dart';
import 'package:donorconnect/language/cubit/language_cubit.dart';
import 'package:donorconnect/language/helper/language.dart';
import 'package:donorconnect/language/services/language_repositoty.dart';
import 'package:donorconnect/services/blood_bank_service.dart';
import 'package:donorconnect/views/pages/main_home/homepage.dart';
import 'package:donorconnect/views/pages/welcome/welcome_screen.dart';
Expand All @@ -13,10 +16,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
// import 'package:riverpod/riverpod.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await LanguageRepository.init();
SharedPreferences prefs = await SharedPreferences.getInstance();
ErrorWidget.builder = (FlutterErrorDetails details) {
return const Material();
Expand Down Expand Up @@ -50,19 +56,28 @@ class MyApp extends StatelessWidget {
BlocProvider(
create: (context) => LocateBloodBanksCubit(BloodBankService()),
),
BlocProvider(
create: (context) => LanguageCubit()..initilize(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
// Main route selection
home: (token != null && !JwtDecoder.isExpired(token!))
? HomePage(token: token!)
: const FrontPage(),
// You can add routes for the verification form
routes: {
'/verification': (context) =>
const VerificationForm(), // Add route for verification form
},
),
child: BlocBuilder<LanguageCubit, Language>(
builder: (context, languageState) {
return MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: Locale(languageState.languageCode),
debugShowCheckedModeBanner: false,
// Main route selection
home: (token != null && !JwtDecoder.isExpired(token!))
? HomePage(token: token!)
: const FrontPage(),
// You can add routes for the verification form
routes: {
'/verification': (context) =>
const VerificationForm(), // Add route for verification form
},
);
}),
);
}
}
Loading