From 1328cc8d1b41b65e3298564a1377ca311ec86ed4 Mon Sep 17 00:00:00 2001 From: Lijo George Date: Thu, 11 Jan 2024 18:34:28 +0530 Subject: [PATCH] Feature:#270-ios-passing language code to all SDK methods for localization Passed languge code to SDK methods such as (DataSharing, GetDataAgreement, GetDataAgreementWithApiKey, CreateIndividual) for localization --- ios/Runner/AppDelegate.swift | 12 ++++++---- .../controllers/dataAgreement_controller.dart | 7 ++++-- ...ivacy_dashboard_credential_controller.dart | 5 +++- .../controllers/register_controller.dart | 23 +++++++++++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index e470a51..935c24f 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -83,9 +83,10 @@ import SwiftMessages let dataAgreementID = arguments?["dataAgreementID"] as? String let baseUrl = arguments?["baseUrl"] as? String let accessToken = arguments?["accessToken"] as? String + let languageCode = arguments?["languageCode"] as? String var data: String? = nil - PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "") + PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "") PrivacyDashboard.updateDataAgreementStatus(dataAgreementId: dataAgreementID ?? "", status: true) PrivacyDashboard.receiveDataBackFromPrivacyDashboard = { dataReceived in let dict = dataReceived["consentRecord"] as? [String: Any] @@ -108,9 +109,10 @@ import SwiftMessages let dataAgreementID = arguments?["dataAgreementID"] as? String let baseUrl = arguments?["baseUrl"] as? String let accessToken = arguments?["accessToken"] as? String + let languageCode = arguments?["languageCode"] as? String var data: String? = nil - PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "") + PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "") PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in debugPrint("Data receieved here:\(resultVal)") let dict = resultVal["dataAgreement"] as? [String: Any] @@ -133,9 +135,10 @@ import SwiftMessages let dataAgreementID = arguments?["dataAgreementID"] as? String let baseUrl = arguments?["baseUrl"] as? String let accessToken = arguments?["accessToken"] as? String + let languageCode = arguments?["languageCode"] as? String var data: String? = nil - PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "") + PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en", accessToken: accessToken ?? "") PrivacyDashboard.readDataAgreementApi(dataAgreementId: dataAgreementID ?? "") { success, resultVal in debugPrint("Data receieved here:\(resultVal)") let dict = resultVal["dataAgreement"] as? [String: Any] @@ -158,8 +161,9 @@ import SwiftMessages let userId = arguments?["userId"] as? String let accessToken = arguments?["accessToken"] as? String let baseUrl = arguments?["baseUrl"] as? String + let languageCode = arguments?["languageCode"] as? String - PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), accessToken: accessToken ?? "") + PrivacyDashboard.configure(withApiKey: apiKey ?? "", withUserId: userId ?? "", withOrgId: "", withBaseUrl: String(baseUrl ?? ""), withLocale: languageCode ?? "en" , accessToken: accessToken ?? "") PrivacyDashboard.createAnIndividual(name: "", email: "", phone: "") { success, resultVal in if success { if let jsonData = try? JSONSerialization.data(withJSONObject: resultVal, options: .prettyPrinted), diff --git a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart index 7693b74..a2f49f3 100644 --- a/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart +++ b/lib/app/modules/dataSharing/controllers/dataAgreement_controller.dart @@ -10,13 +10,14 @@ import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:webview_flutter/webview_flutter.dart'; +import '../../language/controllers/language_controller.dart'; import '../../login/views/login_view.dart'; class DataAgreementContoller extends BaseController { final RegisterController _registerController = Get.find(); WebViewController? controller; var platform = const MethodChannel('io.igrant.data4diabetes.channel'); - + final LanguageController _languageController= Get.find(); var thirdPartyOrgName = "Data4Diabetes"; String? accessToken; var redirectUrl = "https://www.govstack.global/"; @@ -45,6 +46,7 @@ class DataAgreementContoller extends BaseController { return; }, onNavigationRequest: (NavigationRequest request) async { + var languageCode = _languageController.languageCode.value; if (request.url.startsWith(redirectUrl)) { final uri = Uri.parse(request.url); if (uri.queryParameters.containsKey('error')) { @@ -67,7 +69,8 @@ class DataAgreementContoller extends BaseController { "apiKey": PrivacyDashboard().apiKey, "userId": userId, "dataAgreementID": PrivacyDashboard().registrationDataAgreementId, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode }); Map responseMap = json.decode(response); if (responseMap['optIn'] == true) { diff --git a/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart b/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart index b451889..dd0df7e 100644 --- a/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart +++ b/lib/app/modules/developerOptions/controllers/privacy_dashboard_credential_controller.dart @@ -8,11 +8,12 @@ import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../../language/controllers/language_controller.dart'; import '../../launcher/views/launcher_view.dart'; class PrivacyDashboardCredentialController extends BaseController { var platform = const MethodChannel('io.igrant.data4diabetes.channel'); - + final LanguageController _languageController= Get.find(); final TextEditingController apiKeyController = TextEditingController(); final TextEditingController baseUrlController = TextEditingController(); final TextEditingController orgIdController = TextEditingController(); @@ -43,9 +44,11 @@ class PrivacyDashboardCredentialController extends BaseController { } submitButtonAction() async { + var languageCode = _languageController.languageCode.value; var response = await platform.invokeMethod('CreateIndividual', { "apiKey": apiKeyController.text, "baseUrl": baseUrlController.text, + "languageCode": languageCode }); Map responseMap = json.decode(response); Map individual = responseMap['individual']; diff --git a/lib/app/modules/register/controllers/register_controller.dart b/lib/app/modules/register/controllers/register_controller.dart index c4680f8..f47e035 100644 --- a/lib/app/modules/register/controllers/register_controller.dart +++ b/lib/app/modules/register/controllers/register_controller.dart @@ -18,6 +18,7 @@ import 'package:intl_phone_number_input/intl_phone_number_input.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:uuid/uuid.dart'; import 'package:webview_flutter/webview_flutter.dart'; +import '../../language/controllers/language_controller.dart'; import '../../login/controllers/login_controller.dart'; import '/app/core/base/base_controller.dart'; @@ -53,6 +54,7 @@ class RegisterController extends BaseController { String? accessToken; var redirectUrl = "https://www.govstack.global/"; List dataAttributes = [].obs; + final LanguageController _languageController= Get.find(); @override void onInit() { @@ -61,6 +63,7 @@ class RegisterController extends BaseController { } void registerUser() async { + var languageCode = _languageController.languageCode.value; try { SharedPreferences _prefs = await SharedPreferences.getInstance(); var userId = _prefs.getString('privacyDashboarduserId'); @@ -68,7 +71,8 @@ class RegisterController extends BaseController { "apiKey": PrivacyDashboard().apiKey, "userId": userId, "dataAgreementID": PrivacyDashboard().backupAndRestoreDataAgreementId, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode }); Map responseMap = json.decode(response); if (responseMap['optIn'] == true) { @@ -244,9 +248,12 @@ class RegisterController extends BaseController { message: appLocalization.registerExistingUser, ); } else { + var languageCode = _languageController.languageCode.value; var response = await platform.invokeMethod('CreateIndividual', { "apiKey": PrivacyDashboard().apiKey, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode + }); Map responseMap = json.decode(response); @@ -260,6 +267,7 @@ class RegisterController extends BaseController { } onAgreeButtonTap() async { + var languageCode = _languageController.languageCode.value; try { showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); @@ -268,7 +276,8 @@ class RegisterController extends BaseController { "apiKey": PrivacyDashboard().apiKey, "userId": userId , "dataAgreementID": PrivacyDashboard().donateYourDataDataAgreementId, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode }); Map responseMap = json.decode(response); if (responseMap['optIn'] == true) { @@ -298,6 +307,7 @@ class RegisterController extends BaseController { { required String? sharingDataAgreementID, bool? isFlag}) async { + var languageCode = _languageController.languageCode.value; try { showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); @@ -306,7 +316,8 @@ class RegisterController extends BaseController { "apiKey": PrivacyDashboard().apiKey, "userId": userId , "dataAgreementID": sharingDataAgreementID, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode }); Map responseMap = json.decode(response); @@ -344,6 +355,7 @@ class RegisterController extends BaseController { } getDataAgreementWithApiKey({required String? sharingDataAgreementID}) async { + var languageCode = _languageController.languageCode.value; try { showLoading(); SharedPreferences _prefs = await SharedPreferences.getInstance(); @@ -352,7 +364,8 @@ class RegisterController extends BaseController { "apiKey": PrivacyDashboard().apiKey, "userId": userId , "dataAgreementID": sharingDataAgreementID, - "baseUrl": PrivacyDashboard().baseUrl + "baseUrl": PrivacyDashboard().baseUrl, + "languageCode": languageCode }); Map responseMap = json.decode(response);