Skip to content

Commit

Permalink
Rcf 361 - Disable language for which the localization file is not pre…
Browse files Browse the repository at this point in the history
…sent (#245)

* RCF-377 fixed

Signed-off-by: aviral-mishra-hunter <aviralmishra.015@gmail.com>

* Overflow Fix

Signed-off-by: aviral-mishra-hunter <aviralmishra.015@gmail.com>

* Disabled language whose localization file is not available

Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>

* Small fix

Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>

* Added locale codes in a constants file

Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>

* Fixed packet auth page ui

Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>

* Added more locales to constants

Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>

---------

Signed-off-by: aviral-mishra-hunter <aviralmishra.015@gmail.com>
Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>
Co-authored-by: aviral-mishra-hunter <aviralmishra.015@gmail.com>
  • Loading branch information
Piyush7034 and aviralmishra3 authored Jan 12, 2024
1 parent 32aaecf commit 424527a
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 223 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
arb-dir: lib/l10n
arb-dir: assets/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
39 changes: 30 additions & 9 deletions lib/provider/global_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:registration_client/platform_spi/machine_key_service.dart';
import 'package:registration_client/platform_spi/network_service.dart';
import 'package:registration_client/platform_spi/packet_service.dart';
import 'package:registration_client/platform_spi/process_spec_service.dart';
import 'package:registration_client/utils/constants.dart';
import 'package:shared_preferences/shared_preferences.dart';

class GlobalProvider with ChangeNotifier {
Expand Down Expand Up @@ -439,7 +440,7 @@ class GlobalProvider with ChangeNotifier {
int _maxLanguageCount = 0;
Map<String, bool> _mandatoryLanguageMap = {};
List<String?> _notificationLanguages = [];

Map<String, bool> _disabledLanguageMap = {};

List<LanguageData?> get languageDataList => _languageDataList;
Map<String, String> get codeToLanguageMapper => _codeToLanguageMapper;
Expand All @@ -451,11 +452,12 @@ class GlobalProvider with ChangeNotifier {
int get maxLanguageCount => _maxLanguageCount;
Map<String, bool> get mandatoryLanguageMap => _mandatoryLanguageMap;
List<String?> get notificationLanguages => _notificationLanguages;
Map<String, bool> get disabledLanguageMap => _disabledLanguageMap;

initializeLanguageDataList() async {
_languageDataList = await dynamicResponseService.fetchAllLanguages();
await setLanguageConfigData();
createLanguageCodeMapper();
await createLanguageCodeMapper();
notifyListeners();
}

Expand Down Expand Up @@ -509,6 +511,28 @@ class GlobalProvider with ChangeNotifier {
notifyListeners();
}

setDisabledLanguages(Map<String, bool> value) {
_disabledLanguageMap = value;
notifyListeners();
}

Future<bool> isFilePresent(String filePath) async {
try {
await rootBundle.load(filePath);
return true;
} catch (e) {
return false;
}
}

setDisabledLanguage(String langCode) async {
String code = languageCodeToLocale[langCode]!;
String filepath = "assets/l10n/app_$code.arb";
bool isPresent = await isFilePresent(filepath);
_disabledLanguageMap[langCode] = !isPresent;
notifyListeners();
}

setLanguageConfigData() async {
_mandatoryLanguages = await processSpecService.getMandatoryLanguageCodes();
_optionalLanguages = await processSpecService.getOptionalLanguageCodes();
Expand Down Expand Up @@ -538,18 +562,20 @@ class GlobalProvider with ChangeNotifier {
notifyListeners();
}

createLanguageCodeMapper() {
createLanguageCodeMapper() async {
if (_languageDataList.isEmpty) {
_languages = ["eng"];
_codeToLanguageMapper["eng"] = "English";
_languageToCodeMapper["English"] = "eng";
_disabledLanguageMap["eng"] = false;
return;
}
List<String> languageList = [];
for (var element in _languageDataList) {
languageList.add(element!.code);
_codeToLanguageMapper[element.code] = element.name;
_languageToCodeMapper[element.name] = element.code;
await setDisabledLanguage(element.code);
}
_languages = languageList;
}
Expand Down Expand Up @@ -581,12 +607,7 @@ class GlobalProvider with ChangeNotifier {
return;
}
_selectedLanguage = code;
if (code == "kan") {
_appLocale = const Locale("kn");
} else {
String localeCode = code.substring(0, 2);
_appLocale = Locale(localeCode);
}
_appLocale = Locale(languageCodeToLocale[code]!);
notifyListeners();
}

Expand Down
7 changes: 3 additions & 4 deletions lib/ui/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ class _LoginPageState extends State<LoginPage> with WidgetsBindingObserver {

_saveVersionToGlobalParam() async {
String version = context.read<GlobalProvider>().versionNoApp;
if (version.isNotEmpty) {
await context.read<GlobalProvider>().saveVersionToGlobalParam(
"mosip.registration.server_version", version);
}
await context
.read<GlobalProvider>()
.saveVersionToGlobalParam("mosip.registration.server_version", version);
}

_saveAllHeaders() async {
Expand Down
101 changes: 11 additions & 90 deletions lib/ui/machine_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MachineKeys extends StatelessWidget {
width: isMobile
? isMobileSize
? 358.w
: 330.w
: 566.w
: 670.w,
padding: EdgeInsets.only(left: 20.w, right: 19.w),
decoration: const BoxDecoration(
Expand All @@ -73,12 +73,14 @@ class MachineKeys extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context)!.device_credentials,
style: TextStyle(
color: AppStyle.appBlack,
fontSize: isMobileSize ? 18 : 26,
fontWeight: FontWeight.bold,
Expanded(
child: Text(
AppLocalizations.of(context)!.device_credentials,
style: TextStyle(
color: AppStyle.appBlack,
fontSize: isMobileSize ? 18 : 26,
fontWeight: FontWeight.bold,
),
),
),
IconButton(
Expand All @@ -95,27 +97,9 @@ class MachineKeys extends StatelessWidget {
color: AppStyle.dividerColor,
height: 1.h,
),
// Container(
// padding: EdgeInsets.symmetric(
// vertical: 20.h,
// ),
// child: SelectableText(
// machineDetails,
// textDirection: TextDirection.ltr,
// style: const TextStyle(
// fontWeight: FontWeight.w500,
// fontSize: 16,
// ),
// ),
// ),
// Divider(
// color: AppStyle.dividerColor,
// height: 1.h,
// ),
SizedBox(
height: 20.h,
),
// isMobile ? _mobileView() : _tabletView(),
_copyButton(),
SizedBox(
height: 20.h,
Expand Down Expand Up @@ -154,45 +138,6 @@ class MachineKeys extends StatelessWidget {
);
}

// Widget _buttonRow() {
// return Row(
// children: [
// // Expanded(child: _downloadButton()),
// SizedBox(
// width: 10.w,
// ),
// Expanded(child: _copyButton()),
// ],
// );
// }

// Widget _mobileView() {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// _buttonRow(),
// SizedBox(
// height: 29.h,
// ),
// _shareButton(),
// ],
// );
// }

// Widget _tabletView() {
// return Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Expanded(
// child: _shareButton(),
// ),
// Expanded(
// child: _buttonRow(),
// ),
// ],
// );
// }

Widget _copyButton() {
return InkWell(
onTap: () {
Expand All @@ -201,7 +146,7 @@ class MachineKeys extends StatelessWidget {
});
},
child: Container(
height: isMobileSize ? 46.h : 62.h,
height: isMobile && !isMobileSize ? 94.h : 62.h,
decoration: BoxDecoration(
color: AppStyle.appSolidPrimary,
border: Border.all(
Expand All @@ -228,7 +173,7 @@ class MachineKeys extends StatelessWidget {
return InkWell(
onTap: onTap,
child: Container(
height: isMobileSize ? 46.h : 62.h,
height: isMobile && !isMobileSize ? 94.h : 62.h,
decoration: BoxDecoration(
color: AppStyle.appWhite,
border: Border.all(
Expand All @@ -250,28 +195,4 @@ class MachineKeys extends StatelessWidget {
),
);
}

// _shareButton() {
// return InkWell(
// child: Row(
// children: [
// const Icon(
// Icons.share,
// color: AppStyle.appSolidPrimary,
// ),
// SizedBox(
// width: 5.w,
// ),
// const Text(
// 'SHARE',
// style: TextStyle(
// color: AppStyle.appSolidPrimary,
// fontSize: 14,
// fontWeight: FontWeight.bold,
// ),
// ),
// ],
// ),
// );
// }
}
18 changes: 12 additions & 6 deletions lib/ui/process_ui/new_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {
height: 30.h,
),
Container(
width: 376.w,
width: isPortrait && !isMobileSize ? 566.w : 376.w,
padding: EdgeInsets.only(
top: 24.h,
bottom: 28.h,
Expand All @@ -881,7 +881,7 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {
Text(
AppLocalizations.of(context)!.authenticate_using_password,
style: TextStyle(
fontSize: 18,
fontSize: isPortrait && !isMobileSize ? 24 : 18,
fontWeight: semiBold,
color: AppStyle.appBlack),
),
Expand Down Expand Up @@ -956,10 +956,9 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {

_getUsernameTextField() {
return Container(
height: 52.h,
height: isPortrait && !isMobileSize ? 82.h : 52.h,
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(
vertical: 12.h,
horizontal: 12.w,
),
decoration: BoxDecoration(
Expand All @@ -979,6 +978,10 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {
: AppStyle.mobileTextfieldHintText,
border: InputBorder.none,
),
style: TextStyle(
fontSize: isPortrait && !isMobileSize ? 22 : 14,
color: AppStyle.appBlack,
),
onChanged: (v) {
setState(() {
username = v;
Expand All @@ -990,10 +993,9 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {

_getPasswordTextField() {
return Container(
height: 52.h,
height: isPortrait && !isMobileSize ? 82.h : 52.h,
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(
vertical: 12.h,
horizontal: 12.w,
),
decoration: BoxDecoration(
Expand All @@ -1014,6 +1016,10 @@ class _NewProcessState extends State<NewProcess> with WidgetsBindingObserver {
: AppStyle.mobileTextfieldHintText,
border: InputBorder.none,
),
style: TextStyle(
fontSize: isPortrait && !isMobileSize ? 22 : 14,
color: AppStyle.appBlack,
),
onChanged: (v) {
setState(() {
password = v;
Expand Down
Loading

0 comments on commit 424527a

Please sign in to comment.