Skip to content

Commit

Permalink
Merge pull request #2 from Piyush7034/language-switch
Browse files Browse the repository at this point in the history
Integrated l18n files for internationalization
  • Loading branch information
Piyush7034 authored May 15, 2023
2 parents 91a4906 + a3e7568 commit 7f76d8e
Show file tree
Hide file tree
Showing 12 changed files with 396 additions and 77 deletions.
3 changes: 3 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
29 changes: 29 additions & 0 deletions lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"english": "الإنكليزية",
"arabic": "العربية",
"french": "الفرنسية",
"locale": "ara",
"help": "تعليمات",
"mosip": "موسيب",
"welcome": "مرحبا بكم في",
"community_reg_text": "عميل تسجيل المجتمع!",
"info_text": "يرجى تسجيل الدخول للوصول إلى الميزات.",
"login_text": "تسجيل الدخول",
"language": "اللغة",
"username": "اسم المستخدم",
"enter_username": "أدخل اسم المستخدم",
"next_button": "مقبل",
"password": "شعار",
"enter_password": "أدخل كلمة المرور",
"forgot_password": "نسيت كلمة المرور",
"login_button": "تسجيل الدخول",
"back_button": "ظهر",
"login_failed": "فشل تسجيل الدخول.. حاول مرة أخرى!",
"user_validated": "تم التحقق من صحة المستخدم!",
"username_required": "اسم المستخدم مطلوب!",
"password_required": "كلمة المرور مطلوبة!",
"username_exceed": "يجب ألا يتجاوز اسم المستخدم 50 حرفا!",
"password_exceed": "يجب ألا تتجاوز كلمة المرور 50 حرفا!",
"username_incorrect": "لم يتم العثور على المستخدم!",
"password_incorrect": "كلمة المرور غير صحيحة!"
}
29 changes: 29 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"english": "English",
"arabic": "Arabic",
"french": "French",
"locale": "eng",
"help": "HELP",
"mosip": "MOSIP",
"welcome": "Welcome to",
"community_reg_text": "Community Registration Client!",
"info_text": "Please login to access the features.",
"login_text": "Login",
"language": "Language",
"username": "Username",
"enter_username": "Enter Username",
"next_button": "NEXT",
"password": "Password",
"enter_password": "Enter Password",
"forgot_password": "Forgot Password",
"login_button": "LOGIN",
"back_button": "BACK",
"login_failed": "Login Failed..Try Again!",
"user_validated": "User Validated!",
"username_required": "Username is required!",
"password_required": "Password is required!",
"username_exceed": "Username should not exceed 50 characters!",
"password_exceed": "Password should not exceed 50 characters!",
"username_incorrect": "User not found!",
"password_incorrect": "Password incorrect!"
}
29 changes: 29 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"english": "English",
"arabic": "Arabic",
"french": "French",
"locale": "fre",
"help": "AIDE",
"mosip": "MOSIP",
"welcome": "Bienvenue à",
"community_reg_text": "Client d’inscription communautaire",
"info_text": "Veuillez vous connecter pour accéder aux fonctionnalités.",
"login_text": "Connectez-vous",
"language": "Langue",
"username": "Nom d’utilisateur",
"enter_username": "Entrez le nom d’utilisateur",
"next_button": "PROCHAINE",
"password": "Mot de passe",
"enter_password": "Entrez le mot de passe",
"forgot_password": "Mot de passe oublié",
"login_button": "CONNECTEZ-VOUS",
"back_button": "PRÉCÉDENT",
"login_failed": "Echec de la connexion.. Réessayez!",
"user_validated": "Utilisateur validé !",
"username_required": "Le nom d’utilisateur est requis!",
"password_required": "Le mot de passe est requis!",
"username_exceed": "Le nom d’utilisateur ne doit pas dépasser 50 caractères!",
"password_exceed": "Le mot de passe ne doit pas dépasser 50 caractères!",
"username_incorrect": "Utilisateur introuvable !",
"password_incorrect": "Mot de passe incorrect!"
}
105 changes: 55 additions & 50 deletions lib/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:registration_client/app_config.dart';
import 'package:registration_client/const/utils.dart';

import 'package:registration_client/credentials_page.dart';
import 'package:flutter/services.dart';
import 'package:registration_client/provider/app_language.dart';
import 'package:registration_client/registration_client.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class LoginPage extends StatefulWidget {
const LoginPage({super.key});
Expand All @@ -32,20 +35,22 @@ class _LoginPageState extends State<LoginPage> {
String username = '';
String password = '';
bool isUserValidated = false;
List<String> _languages = ['English', 'Arabic', 'French'];
String _selectedLanguage = 'English';
List<String> _languages = ['eng', 'ara', 'fre'];
Map<String, String> mp = {};
final _formKey = GlobalKey<FormState>();
TextEditingController usernameController = TextEditingController();
TextEditingController passwordController = TextEditingController();

@override
void initState() {
super.initState();
mp['eng'] = "English";
mp['ara'] = "Arabic";
mp['fre'] = "French";
}

@override
Widget build(BuildContext context) {
// ScreenUtil.init(context);
isMobile = MediaQuery.of(context).orientation == Orientation.portrait;
double h = ScreenUtil().screenHeight;
double w = ScreenUtil().screenWidth;
Expand All @@ -68,7 +73,7 @@ class _LoginPageState extends State<LoginPage> {
padding: EdgeInsets.symmetric(
horizontal: isMobile ? 16.w : 80.w,
),
child: isMobile ? _mobileView() : _tabletView(),
child: _mobileView(),
),
],
),
Expand Down Expand Up @@ -177,7 +182,7 @@ class _LoginPageState extends State<LoginPage> {
),
child: Center(
child: Text(
'HELP',
AppLocalizations.of(context)!.help,
style: Utils.mobileHelpText,
),
),
Expand All @@ -200,11 +205,11 @@ class _LoginPageState extends State<LoginPage> {
isMobile ? CrossAxisAlignment.center : CrossAxisAlignment.start,
children: [
Text(
'Welcome to',
AppLocalizations.of(context)!.welcome,
style: Utils.mobileWelcomeText,
),
Text(
'Community Registration Client!',
AppLocalizations.of(context)!.community_reg_text,
style: Utils.mobileCommunityRegClientText,
)
],
Expand All @@ -219,7 +224,7 @@ class _LoginPageState extends State<LoginPage> {
horizontal: isMobile ? 52.w : 0,
),
child: Text(
'Please login to access all the features.',
AppLocalizations.of(context)!.info_text,
style: Utils.mobileInfoText,
),
);
Expand Down Expand Up @@ -266,7 +271,7 @@ class _LoginPageState extends State<LoginPage> {
Container(
height: 34.h,
child: Text(
'Login',
AppLocalizations.of(context)!.login_text,
style: Utils.mobileHeaderText,
),
),
Expand All @@ -281,13 +286,14 @@ class _LoginPageState extends State<LoginPage> {
}

Widget _usernameComponent() {
final appLanguage = Provider.of<AppLanguage>(context, listen: false);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 17.h,
child: Text(
'Language',
AppLocalizations.of(context)!.language,
style: Utils.mobileTextfieldHeader,
),
),
Expand Down Expand Up @@ -315,13 +321,12 @@ class _LoginPageState extends State<LoginPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
DropdownButton(
value: _selectedLanguage,
value: context.watch<AppLanguage>().selectedLanguage,
underline: const SizedBox.shrink(),
icon: const SizedBox.shrink(),
onChanged: (newValue) {
setState(() {
_selectedLanguage = newValue!;
});
context.read<AppLanguage>().selectedLanguage = newValue!;
appLanguage.changeLanguage(Locale(newValue));
},
items: _languages.map((lang) {
return DropdownMenuItem(
Expand All @@ -330,7 +335,7 @@ class _LoginPageState extends State<LoginPage> {
height: 17.h,
// width: 47.w,
child: Text(
lang,
mp[lang]!,
style: Utils.mobileDropdownText,
),
),
Expand All @@ -352,7 +357,7 @@ class _LoginPageState extends State<LoginPage> {
Container(
height: 17.h,
child: Text(
'Username',
AppLocalizations.of(context)!.username,
style: Utils.mobileTextfieldHeader,
),
),
Expand All @@ -362,8 +367,8 @@ class _LoginPageState extends State<LoginPage> {
Container(
height: 52.h,
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(
left: 17.w,
padding: EdgeInsets.symmetric(
horizontal: 17.w,
),
decoration: BoxDecoration(
border: Border.all(
Expand All @@ -377,7 +382,7 @@ class _LoginPageState extends State<LoginPage> {
child: TextField(
controller: usernameController,
decoration: InputDecoration(
hintText: 'Enter Username',
hintText: AppLocalizations.of(context)!.enter_username,
hintStyle: Utils.mobileTextfieldHintText,
border: InputBorder.none,
),
Expand All @@ -392,9 +397,9 @@ class _LoginPageState extends State<LoginPage> {
username = usernameController.text;
});
if (username.isEmpty) {
_showInSnackBar("Username is required!");
} else if(username.length > 50) {
_showInSnackBar("Length of Username should not be greater than 50!");
_showInSnackBar(AppLocalizations.of(context)!.username_required);
} else if (username.length > 50) {
_showInSnackBar(AppLocalizations.of(context)!.username_exceed);
} else if (!isUserValidated) {
_validateUsername().then((value) {
_showInSnackBar(loginResponse);
Expand All @@ -415,7 +420,7 @@ class _LoginPageState extends State<LoginPage> {
),
child: Center(
child: Text(
'NEXT',
AppLocalizations.of(context)!.next_button,
style: Utils.mobileButtonText,
),
),
Expand All @@ -432,7 +437,7 @@ class _LoginPageState extends State<LoginPage> {
Container(
height: 17.h,
child: Text(
'Password',
AppLocalizations.of(context)!.password,
style: Utils.mobileTextfieldHeader,
),
),
Expand Down Expand Up @@ -463,7 +468,7 @@ class _LoginPageState extends State<LoginPage> {
});
},
decoration: InputDecoration(
hintText: 'Enter Password',
hintText: AppLocalizations.of(context)!.enter_password,
hintStyle: Utils.mobileTextfieldHintText,
border: InputBorder.none,
),
Expand All @@ -478,7 +483,7 @@ class _LoginPageState extends State<LoginPage> {
height: 17.h,
alignment: Alignment.centerRight,
child: Text(
'Forgot Password?',
AppLocalizations.of(context)!.forgot_password,
style: Utils.mobileForgotPasswordText,
),
),
Expand All @@ -489,11 +494,11 @@ class _LoginPageState extends State<LoginPage> {
InkWell(
onTap: () {
debugPrint('Username: $username and Password: $password');
if(password.isEmpty) {
_showInSnackBar("Password is required!");
if (password.isEmpty) {
_showInSnackBar(AppLocalizations.of(context)!.password_required);
return;
} else if(password.length > 50) {
_showInSnackBar("Length of Password should not be greater than 50!");
} else if (password.length > 50) {
_showInSnackBar(AppLocalizations.of(context)!.password_exceed);
}
setState(() {
isLoggingIn = true;
Expand All @@ -520,12 +525,12 @@ class _LoginPageState extends State<LoginPage> {
child: Center(
child: isLoggingIn
? const CircularProgressIndicator(
color: Utils.appWhite,
)
color: Utils.appWhite,
)
: Text(
'LOGIN',
style: Utils.mobileButtonText,
),
AppLocalizations.of(context)!.login_text,
style: Utils.mobileButtonText,
),
),
),
),
Expand Down Expand Up @@ -553,7 +558,7 @@ class _LoginPageState extends State<LoginPage> {
),
child: Center(
child: Text(
'BACK',
AppLocalizations.of(context)!.back_button,
style: Utils.mobileBackButtonText,
),
),
Expand All @@ -575,18 +580,18 @@ class _LoginPageState extends State<LoginPage> {
);
}

Widget _tabletView() {
return SingleChildScrollView(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_appCombinedTextComponent(),
SizedBox(
width: 41.w,
),
_loginComponent(),
],
),
);
}
// Widget _tabletView() {
// return SingleChildScrollView(
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// _appCombinedTextComponent(),
// // SizedBox(
// // width: 41.w,
// // ),
// _loginComponent(),
// ],
// ),
// );
// }
}
Loading

0 comments on commit 7f76d8e

Please sign in to comment.